iphone - 使用单个方法调用设置 UIButton 的标题?

标签 iphone uibutton

我想通过代码设置 UIButton 的标题。我发现自己必须为 UIControlStateNormal、UIControlStateHighlighted、UIControlStateDisabled、UIControlStateSelected 调用 -[UIButton setTitle:forState:]。这甚至没有考虑到这些状态的所有组合。

不用说,这很烦人。我是否可以进行一次调用,将一个字符串设置为所有州的标题? (因为,我假设在 95% 的情况下,这是期望的行为?)

最佳答案

是的,你当然可以。 From the docs :

In general, if a property is not specified for a state, the default is to use the UIControlStateNormal value. If the value for UIControlStateNormal is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.

因此,只需设置 UIControlStateNormal 的标题即可。

关于iphone - 使用单个方法调用设置 UIButton 的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2479513/

相关文章:

ios - 根据 UIButton 的标题调整其宽度

iOS 将我们自己的位置分享给其他人?

iphone - iOS:增加选项卡项目的对比度

ios - 通过 Twilio 在 iOS 中使用后台进程

iphone - NSData initWithContentsOfURL : options: errorPtr: delegate object?

ios - 如何为具有动态宽度的 UIButtons 设置背景?

ios - 如何在 UILabel 中的不同字符串上显示两个单独的链接?

ios - Swift:删除层,而不删除 UITableViewCell 中的 UIView

javascript - 在 iPhone 上查看完整网站,而非手机版

ios - 按钮框架在运行时变化