ios - 如何在 swift 3 中设置按钮标签?

标签 ios swift uibutton swift3

<分区>

@IBOutlet weak var catParentIdButton: UIButton!

我有这段代码,现在我想以编程方式编写按钮标签。
在 swift 3.0 中编写按钮标签的语法是什么?

最佳答案

Swift 3.0 中的方法签名发生了变化

func setTitle(_ title: String?, 
      for state: UIControlState) // Use this method to set the title for the button

例子:

btn.setTitle(title: "Title", for: .normal)

注意 btn 控件的默认状态更改为 .Normal.normal

// previous 
public static var Normal: UIControlState { get }

// Swift 3.0
static var normal: UIControlState { get }

关于ios - 如何在 swift 3 中设置按钮标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40080483/

相关文章:

ios - 蓝牙随机断开

ios - 带有客户端证书的 SecTrustSetAnchorCertificates

arrays - 快速显示数组中先前输入的项目

ios - 约束 LefAnchor 常量不更新

ios - 如何正确使用 prepare for segue for Structs?

iphone - 我想将 UIButton 移动到特定位置,例如在网格上

ios - 将操作按钮图形设置为 UIButton

ios - 如何在 UIPopoverController 中设置 UITableView 的背景颜色?

ios - Objective-C/CocoaHTTPServer - 是否可以将响应返回到应用程序?

swift - 我的按钮在 iPhone 6 和 6 plus 上居中,但在 iPhone 5 上则不然