I am attempting something relatively simple. I have a UIButton that loads with an image:
@IBOutlet var peer5Outlet: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
peer5Outlet.enabled = true
var img = UIImage(named: "camera")
peer5Outlet.setImage(UIImage(named: "camera"),forState: UIControlState.Normal) }
Once it is loaded, I simply want to update that image by calling a method:
func updateButtonImage() {
peer5Outlet.imageView!.image = UIImage(named: "connected")!
print("peer5Outlet.imageView!.image = \(peer5Outlet!.imageView!.image!)")
}
However, I am still unable to update the image; the original image never changes in the view.
Perhaps I am missing some sort of view reload method?
Update your updateButtonImage function to
func updateButtonImage() {
peer5Outlet.setImage(UIImage(named: "connected"), forState: .Normal)
print("peer5Outlet.imageView!.image = \(peer5Outlet!.imageView!.image!)")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With