更改UIButton图像获取按钮位置更改

时间:2012-06-26 04:55:15

标签: iphone xcode uibutton

我正在按钮点击时更改UIButton图像,但它会从原始到左侧获得位置更改。我不知道为什么会这样。 下面是按钮。当我选择第二个按钮时,它会改变图像并到达左侧。如何解决此错误?

以下是我的代码

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

}

2 个答案:

答案 0 :(得分:1)

我对你的情况不是百分之百确定,但通常是因为两个图像中的透明空间,请在Photoshop中重叠你的图像并确保两个图像应该具有相同的边距,并且也应该具有相同的尺寸。

答案 1 :(得分:0)

setImage不会拉伸您的图片以填充按钮的框架,它将设置为按钮的中心。

确保按钮的图像大小和框架相等。

否则,您可以使用setBackgroundImage来拉伸图像以填充按钮框。

相关问题