【问题标题】:Changing the UIButton Images get button postion changed更改 UIButton 图像获取按钮位置更改
【发布时间】:2012-06-26 04:55:15
【问题描述】:

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

}

【问题讨论】:

  • 您的图片尺寸可能不同
  • @Eric 是的,你是对的,它们的尺寸不同
  • 在那种情况下,图像似乎在移动?

标签: iphone xcode uibutton


【解决方案1】:

我不是百分百确定你的情况,但它通常是因为两个图像中的透明空间而发生的,请在 Photoshop 中重叠你的图像,并确保两个图像应该具有相同的边距并且应该具有相同的大小。

【讨论】:

    【解决方案2】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-27
      • 2014-01-23
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多