MRafiq
MRafiq

Reputation: 27

Changing the UIButton Images get button postion changed

I am changing the UIButton image on button click but it gets postion changes from original to left side. I don't know why this is happening. Below is the button. When I select the second button, it changes image and gets to the left side. How do I fix this error ?

Below is my code

  -(IBAction)locationOneButtonAction{


UIImage *buttonImage = [UIImage imageNamed:@"radiogreen.png"];

UIImage *buttonImageOne=[UIImage imageNamed:@"radiowhite.png"];


[locationOneButton setImage:buttonImage forState:UIControlStateNormal];

[locationOneButton setImage:buttonImage forState:UIControlStateNormal];


[locationThreeButton  setImage:buttonImageOne forState:UIControlStateNormal];
[locationTwoButton  setImage:buttonImageOne forState:UIControlStateNormal];

[locationFourButton  setImage:buttonImageOne forState:UIControlStateNormal];

[locationFiveButton  setImage:buttonImageOne forState:UIControlStateNormal];
[locationSixButton  setImage:buttonImageOne forState:UIControlStateNormal];


resturantLocation=@"Common Man - Bedford, MA";

}

Upvotes: 0

Views: 97

Answers (2)

saadnib
saadnib

Reputation: 11145

I am not hundred percent sure about your case but it usually happen because of transparent space in both images, please overlap your images in Photoshop and make sure both images should have same margins and also should be of same size.

Upvotes: 1

DivineDesert
DivineDesert

Reputation: 6954

setImage wont stretch your image to fill frame of your button, it will set to center of button.

Make sure your image size and frame of your button is equal.

Else you can use setBackgroundImage which is will stretch your image to fill frame of button.

Upvotes: 0

Related Questions