V
V
Viktor2019-11-08 03:31:04
Swift
Viktor, 2019-11-08 03:31:04

How to access layer properties of UIControl subclasses in iOS 13/XCode 11 using UIKIt?

Faced the following situation: There is a simple button (UIButton) which should have borders (borderWidth/borderColor). Previously, this could be done by creating your own class with inheritance from UIButton.
For example:

class BorderButton: UIButton {

    override class func awakeFromNib() {
        super.awakeFromNib()
        layer.borderWidth = 3.0
        layer.borderColor = UIColor.white.cgColor
    }

}

Now this code throws an error:
Instance member 'layer' cannot be used on type 'BorderButton'

I tried to get and change these properties through proxy appearence().layer - but this did not work.
I did not find anything about this in the release notes / google (although I may have searched badly).
Actually the question is - tell me in which direction to "dig"? Does dark/light mode interfere? Or write your own constructor and your own buttonType?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2019-11-08
@koders

to write correctly:

override func awakeFromNib() {
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question