Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the image of UIButton programmatically?

Tags:

ios

xcode8

swift3

I want to set the image of a UIButton on a particular event. This is what I did:

btn.setImage(UIImage(named: "star"))
like image 904
Pulkit Aggarwal Avatar asked Jun 10 '26 07:06

Pulkit Aggarwal


1 Answers

Objective-C

UIImage *img = [UIImage imageNamed:@"star.png"];                
[btn setImage:img forState:UIControlStateNormal];              

Swift 3

let img = UIImage(named: "star")
btn.setImage(img , forState: .normal)
like image 124
Peeyush karnwal Avatar answered Jun 12 '26 23:06

Peeyush karnwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!