【问题标题】:How to disable upside-down fliping of UIButton image when it's touched?触摸时如何禁用 UIButton 图像的上下翻转?
【发布时间】:2011-12-06 12:59:51
【问题描述】:

我为“UIControlStateNormal”为 UIButton 设置了一个图像,如果我按下此按钮,图像会被遮住并在我按住它的时间内上下翻转。

阴影是可以的,但是如果我不想为状态“UIControlStateHighlighted”设置自定义图像,如何禁用翻转? 感谢您的帮助

我制作按钮的代码是:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.tag=i;
        [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        button.frame = CGRectMake(xakt, yakt, a, b);

然后我使用- (void)setImage:(UIImage *)image forState:(UIControlState)state 函数设置按钮图像。 我包括了 2 张图片,第一张处于正常状态,第二张处于按下状态

【问题讨论】:

  • 我从未见过翻转的图像...您的按钮有什么特别之处?请发布您如何创建图像以及如何创建按钮的代码。
  • 请张贴代码。我不明白你的问题到底是什么?

标签: iphone xcode ipad ios5


【解决方案1】:

我对上述这种行为的观察(单击时按钮上的图像反转)仅限于以下情况:

  1. 按钮的图像是使用设置的 - (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state 状态为UIControlStateNormal

  2. 可能不需要此条件,但UIImageimageOrientationUIImageOrientationDown

为剩余的两个控件状态指定背景图像应该可以解决问题。

UIButton *button = ...
UIImage *image = ...
[button setBackgroundImage:image forState:UIControlStateNormal];
// Specify same image for selected / highlighted states
[button setBackgroundImage:image forState:UIControlStateSelected];
[button setBackgroundImage:image forState:UIControlStateHighlighted];

注意:

[button setBackgroundImage:image
                  forState:UIControlStateNormal |
                           UIControlStateSelected |
                           UIControlStateHighlighted];

没用。

【讨论】:

    【解决方案2】:

    您似乎没有在 UIButton 实例上使用 - (void)setImage:(UIImage *)image forState:(UIControlState)state

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 2021-08-15
      相关资源
      最近更新 更多