Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton background VS UIButton imageview.view

What is the difference between UIButton background and UIButton imageview.view I tried myButton.imageView.image=[UIImage imageNamed:@"image.png"]; then nothing happens, but when I use [myButton setBackgroundImage:[UIImage imageNamed:@"image.png"] forState:UIControlStateNormal]; button's background changes.

Thanks !

like image 413
Alaa Eldin Avatar asked Jan 17 '23 14:01

Alaa Eldin


1 Answers

myButton.imageView.image is a readonly property and thus can't be change like this. whereas setBackgroundImage is a method which sets the background properly.

//EDIT

the method setImage for UIButton REQUIRES two arguments,

setImage:(UIImage *) forState:(UIControlState)

thus using the above mentioned method works fine and other doesn't.

like image 78
Naveed Abbas Avatar answered Jan 30 '23 01:01

Naveed Abbas