iPr*_*ram 0 uibutton ios swift3
当我们想要设置一个 UIButton 的文本时,我们需要执行以下代码:
myButton.setTitle("My Text", forState: .normal)
Run Code Online (Sandbox Code Playgroud)
唯一的问题是,当文本更改时,动画会像这样发生:
有没有办法在没有动画的情况下设置按钮的标题?
我希望按钮充当标准的 UILabel,但是我也希望它在按下时调用一个函数。
您可以在 UIView 中设置值performWithoutAnimation,它会按照它的说明进行操作。但是您还需要调用,layoutIfNeeded以便在块期间进行重新布局。
UIView.performWithoutAnimation {
self.myButton.setTitle(newTitle, forState: .Normal)
self.myButton.layoutIfNeeded()
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1429 次 |
| 最近记录: |