【问题标题】:UIButton not Blinking on TouchUIButton在触摸时不闪烁
【发布时间】:2015-07-26 21:01:53
【问题描述】:

我有一个以编程方式创建的 UIButton,位于 UIView 内(层次结构中没有其他级别)。按钮确实正确响应了touchUpInside 事件,但由于某种原因,文本在触摸时没有表现出其正常的“闪烁”行为。如果有人知道可能导致这种情况的原因,我想找回它。

其他说明:我有userInteractionEnabled = TRUE,并且我的代码中没有自定义动画。相关实例化代码(UIColor 名称来自自定义类别):

self.loginButton = [[UIButton alloc] init];
self.loginButton.backgroundColor = [UIColor MPBlackColor];
[self.loginButton setTitle:@"LOG IN" forState:UIControlStateNormal];
[self.loginButton setTitleColor:[UIColor MPGreenColor] forState:UIControlStateNormal];
self.loginButton.titleLabel.font = [UIFont fontWithName:@"Oswald-Bold" size:24.0f];

【问题讨论】:

  • 为突出显示的状态赋予标题颜色。
  • 我以前从来没有这样做过,除非我在颜色选择上进行一些试验和错误,否则效果似乎不一样......这种行为最近有变化吗?编辑:当我将按钮放到空白故事板上时,它仍然会像我习惯的那样闪烁
  • 就像我说的,它的效果不太一样,但它会起作用。谢谢

标签: ios objective-c uibutton


【解决方案1】:

问题是您的正常状态自定义颜色也适用于突出显示状态,除非您为突出显示状态赋予单独的颜色。所有按钮状态相关值都是如此。

【讨论】:

  • 另外分配一个色调颜色而不是标题颜色!
  • 哦,另一个问题是您在使用 alloc init 创建按钮时抛弃了标准行为。这不是你制作按钮的方式!使用 buttonWithStyle 并请求一个系统按钮。
【解决方案2】:

为正常和突出显示的按钮状态应用颜色。在斯威夫特:

loginButton.setTitleColor(.green, for: .normal)
loginButton.setTitleColor(.green, for: .highlighted)

注意:相同的逻辑适用于带有图像的闪烁按钮。您应该同时设置.normal.highlighted 状态

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多