在ios7中,我的UIButton标题在错误的时间动画进出——迟到。在iOS 6上不出现此问题。我用的是:

[self setTitle:text forState:UIControlStateNormal];

我更希望这能立即发生,而不是一个空白的框架。这种眨眼特别分散注意力,并将注意力从其他动画中转移开。


当前回答

设置UIButton类型为自定义。这应该会删除淡入和淡出动画。

其他回答

使用performWithoutAnimation:方法,然后强制布局立即发生,而不是稍后。

[UIView performWithoutAnimation:^{
  [self.myButton setTitle:text forState:UIControlStateNormal];
  [self.myButton layoutIfNeeded];
}];

Xhacker Liu扩展转换为Swift 3:

extension UIButton {
    func setTitleWithoutAnimation(title: String?) {
        UIView.setAnimationsEnabled(false)

        setTitle(title, for: .normal)

        layoutIfNeeded()
        UIView.setAnimationsEnabled(true)
    }
}

斯威夫特5

myButton.titleLabel?.text = "title"
myButton.setTitle("title", for: .normal)

你可以从标题标签层中删除动画:

    [[[theButton titleLabel] layer] removeAllAnimations];

设置UIButton类型为自定义。这应该会删除淡入和淡出动画。