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

man*_*tes 6 uibutton ios swift swift3

@IBOutlet weak var catParentIdButton: UIButton!
Run Code Online (Sandbox Code Playgroud)

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

Sah*_*hil 13

方法签名在Swift 3.0中更改

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

例:

btn.setTitle(title: "Title", for: .normal)
Run Code Online (Sandbox Code Playgroud)

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

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

// Swift 3.0
static var normal: UIControlState { get }
Run Code Online (Sandbox Code Playgroud)