Siddiqui
Siddiqui

Reputation: 7840

How do I get an image from an UIButton?

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 Guide me.

Upvotes: 19

Views: 16953

Answers (3)

Maverick
Maverick

Reputation: 3259

Swift 3.0 syntax

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

Upvotes: 2

Aurum Aquila
Aurum Aquila

Reputation: 9126

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"];

Upvotes: 0

zoul
zoul

Reputation: 104065

How about this?

UIImage *img = [button imageForState:UIControlStateNormal];

Upvotes: 61

Related Questions