What uses the UIControlState UIButton "application"?

I went through an apple doc , but it just states that its

Additional control status flags available for use by the application.

Its just a getter method when it is installed?

+6
source share
1 answer

applicationand reservedare mostly markers. This is more understandable when viewing the objective-c documentation for them:

disabled :UIControlStateDisabled = 1 << 1

application :UIControlStateApplication = 0x00FF0000

reserved :UIControlStateReserved = 0xFF000000

, a UIControlState, , UIControl. 17 - 24 ( 1 << 16 1 << 23) , 25 - 32 ( 1 << 24 1 << 31) - .

, Apple / 16 , , 8 .

, . :

let myFlag = UIControlState(rawValue: 1 << 18)

class MyButton : UIButton {
    var customFlags = myFlag
    override var state: UIControlState {
        get {
            return [super.state, customFlags]
        }
    }

    func disableCustom() {
        customFlags.remove(myFlag)
    }
}

let myButton = MyButton()
print(myButton.state.rawValue) // 262144 (= 2^18)
myButton.isEnabled = false
myButton.isSelected = true
print(myButton.state.rawValue) // 262150 (= 262144 + 4 + 2)
myButton.disableCustom()
print(myButton.state.rawValue) // 6 (= 4 + 2) 
+2

Source: https://habr.com/ru/post/1016955/


All Articles