ios - 使选定的按钮标题标签为大写

标签 ios swift uibutton

我有一个标题为“Button”的按钮。经过一些操作后,此按钮获得“已选择”状态。当它被选中时,它有不同的文本颜色,很容易在界面构建器中指定。

问题是我还想将它的标题设置为大写。我不知道怎么做。

最佳答案

您可以通过属性检查器为 UIButton 的选定状态设置标题。 请找到下图:

enter image description here

您也可以通过编程方式设置它。

objective-C

[btn setTitle:btn.titleLabel.text.uppercaseString forState:UIControlStateSelected];

swift

 btn.setTitle(btn.titleLabel!.text.uppercaseString, forState: .Selected)

关于ios - 使选定的按钮标题标签为大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099576/

相关文章:

ios - Swift:堆栈 View 不显示完整的 subview

ios - 子类化 iOS 控件 - 代码与 Storyboard

ios - UIButton 文本不会保持变化

ios - Swift - 如果项目滚动一点,UICollection 回弹得太快

ios - clang:错误:没有这样的文件或目录: '/Users/waterskiingmithrill/Development/iPhone/Event/Event_Prefix.pch'

ios - 如何将 MonoTouch.Dialog 元素嵌入到 ViewController 中?

ios - 如何将适用于 iOS 的 Admob 横幅放在底部中心?

swift - 通过启动 App 进行 Coremotion 和 iPhone 定位

ios - 如何向放置在 UIStackView 中以编程方式创建的 UIButton 添加约束

ios - Safari web 检查器只显示源、控制台和审计