Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set button label in swift 3? [duplicate]

@IBOutlet weak var catParentIdButton: UIButton!

I have this code and now I want to write the button label programmatically.
What will be the syntax to write the label of the button in swift 3.0?

like image 913
mani booleanbites Avatar asked Oct 17 '16 07:10

mani booleanbites


1 Answers

Method Signature changed in Swift 3.0

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

example:

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

Note default state of a btn control is changed to .Normal to .normal.

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

// Swift 3.0
static var normal: UIControlState { get }
like image 63
Sahil Avatar answered Oct 05 '22 18:10

Sahil