UIControlState.Normal 不可用 [英] UIControlState.Normal is Unavailable

查看:15
本文介绍了UIControlState.Normal 不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前对于UIButton 实例,您可以为setTitlesetImage 传入UIControlState.Normal..Normal 不再可用,我应该用什么代替?

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

(这是一个规范的问答对,以防止与 iOS 10 和 Swift 3 的 UIButtonUIControl 更改相关的重复问题泛滥)

(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)

推荐答案

Swift 3 更新:

Swift 3 update:

看起来 Xcode 8/Swift 3 把 UIControlState.normal 带回来了:

It appears that Xcode 8/Swift 3 brought UIControlState.normal back:

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 中删除.对于普通"选项,使用空数组构造空选项集.

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: [])

这篇关于UIControlState.Normal 不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆