2012-06-26 97 views
0

我正在更改按钮单击上的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]; 


[email protected]"Common Man - Bedford, MA"; 

}

+2

您的图片尺寸可能不尽相同 – Eric

+0

@Eric是的,你是对的,它们的尺寸不一样 – MRafiq

+0

在那种情况下,为什么图像似乎移动? – Eric

回答

1

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

0

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

确保您的图片大小和按钮框架相同。

否则您可以使用setBackgroundImage这将拉伸您的图像填充按钮的框架。