gpt4 book ai didi

ios - UIControlState.Normal 不可用

转载 作者:IT王子 更新时间:2023-10-29 05:22:59 26 4
gpt4 key购买 nike

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

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

(这是一个规范的问答对,以防止与此 UIButtonUIControl 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, 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: [])

关于ios - UIControlState.Normal 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37800342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com