简体   繁体   中英

Set the image of UIButton programmatically?

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

btn.setImage(UIImage(named: "star"))

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM