JAL JAL - 5 months ago 193
Swift Question

UIControlState.Normal is Unavailable

Previously for

UIButton
instances, you were able to pass in
UIControlState.Normal
for
setTitle
or
setImage
.
.Normal
is no longer available, what should I use instead?

let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
btn.setTitle("title", for: .Normal) // does not compile


(This is a canonical Q&A pair to prevent the flood of duplicate questions related to this
UIButton
and
UIControl
changes with iOS 10 and Swift 3)

JAL JAL
Answer

UIControlState.Normal has been renamed to UIControlState.normal and removed from the iOS SDK. For "Normal" options, use an empty array to construct an empty option set.

let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 20, height: 20))

// Does not work
btn.setTitle("title", for: .Normal) // 'Normal' has been renamed to 'normal'
btn.setTitle("title", for: .normal) // 'normal' is unavailable: use [] to construct an empty option set

// Works
btn.setTitle("title", for: [])