我希望在运行时移除UIButton的图像并替换为标题。虽然我能够将标题添加到UIButton上,但无法删除图像。有人能给些建议吗?
我希望在运行时移除UIButton的图像并替换为标题。虽然我能够将标题添加到UIButton上,但无法删除图像。有人能给些建议吗?
这是这样的吗? [myButton setImage:nil forState:UIControlStateNormal];
针对Swift 3用户
self.myButton.setImage(nil, for: .normal)
您的图片必须是按钮的背景图片(否则您将看不到标题文本,我相信图像属性会覆盖标题属性)。因此,您必须执行以下操作:
[myButton setBackgroundImage:nil ...
final private func adaptUI(){
if self.presentsFlag{
let imgP = UIImage(named: "present_checked")
let imgA = UIImage(named: "absent")
self.presentBtn.image = imgP
self.absentBtn.image = imgA
}else{
let imgP = UIImage(named: "present")
let imgA = UIImage(named: "absent_checked")
self.presentBtn.image = imgP
self.absentBtn.image = imgA
}
}