我在Xcode 8上使用iOS10将我的应用更新为Swift 3 我收到错误:
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
}
答案 0 :(得分:7)
与任何其他选项集一样:
button.setTitle("", for: [])
其中[]
代表.normal
(.normal
的值为0
)。
请注意,我们可以在一次调用中使用多个状态:
button.setTitle("", for: [.selected, .disabled])
这就是UIControlState
已更改为选项集的原因。