开发者

How do I get an image from an UIButton?

开发者 https://www.devze.com 2023-02-07 01:00 出处:网络
I have Custom Buttons in my application in which I have set images. I want to get image from button and stored in UIImage variable. Kindly G开发者_Python百科uide me.How about this?

I have Custom Buttons in my application in which I have set images. I want to get image from button and stored in UIImage variable. Kindly G开发者_Python百科uide me.


How about this?

UIImage *img = [button imageForState:UIControlStateNormal];


Swift 3.0 syntax

let image: UIImage = yourButton.image(for: .normal)!


UIImage *myNewImage = [UIButton imageForState:UIControlStateNormal];

Though this isn't very good design practice. I would do this:

UIImage *myNewImage = [UIImage imageNamed:@"name of image that is in your bundle"];

0

精彩评论

暂无评论...
验证码 换一张
取 消