setTitle(_ title: String?, for state: UIControlState) .Normal 状态在哪里?

setTitle(_ title: String?, for state: UIControlState) where is .Normal state?

我正在将我的应用更新到 Swift 3 iOS10 Xcode 8 我得到一个错误:

Btn.setTitle('str', forState: .Normal)

.Normal 不再是 UIControlState 的枚举类型。 我应该为这个状态使用哪种类型的 UIControlState?

Apple 枚举现在定义为

public struct UIControlState : OptionSet {

   public init(rawValue: UInt)


   public static var highlighted: UIControlState { get } // used when UIControl isHighlighted is set

   public static var disabled: UIControlState { get }

   public static var selected: UIControlState { get } // flag usable by app (see below)

   @available(iOS 9.0, *)
   public static var focused: UIControlState { get } // Applicable only when the screen supports focus

   public static var application: UIControlState { get } // additional flags available for application use

   public static var reserved: UIControlState { get } // flags reserved for internal framework use 
}

与任何其他选项集一样:

button.setTitle("", for: [])

其中[]代表.normal.normal的值为0)。

请注意,我们可以在一次调用中使用多个状态:

button.setTitle("", for: [.selected, .disabled])

这就是 UIControlState 已更改为选项集的原因。