我正在尝试使用Swift更改UIButton的图像…我该怎么办
这是OBJ-C代码。但是我不知道Swift:
[playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
从您的Obc-C代码中,我认为您想为按钮设置图片,因此请尝试以下方式:
let playButton = UIButton(type: .Custom) if let image = UIImage(named: "play.png") { playButton.setImage(image, forState: .Normal) }
简而言之:
playButton.setImage(UIImage(named: "play.png"), forState: UIControlState.Normal)
对于Swift 3:
let playButton = UIButton(type: .custom) playButton.setImage(UIImage(named: "play.png"), for: .normal)