以前对于UIButton实例,您可以传入setTitle或set
Image的UIControlState.normal.正常现在不再可用了,应该用什么呢?
let btn = UIButton(frame: CGRect(x: 0,y: 0,width: 20,height: 20)) btn.setTitle("title",for: .normal) // does not compile
(这是一个规范的Q& A对,以防止与这个UIButton和UIControl有关的重复问题的洪水与iOS 10和Swift 3的变化)
解决方法
Swift 3更新:
看来Xcode 8 / Swift 3带来了UIControlState.normal:
public struct UIControlState : OptionSet { public init(rawValue: UInt) public static var normal: UIControlState { get } 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 }
UIControlState.normal已重命名为UIControlState.normal并从iOS SDK中删除.对于“正常”选项,使用空数组来构造一个空选项集.
let btn = UIButton(frame: CGRect(x: 0,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: [])
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。