简体   繁体   中英

Make UIView class conform UILayoutSupport protocol

For some reason I wish to use UIView instances as UILayoutSupport .

UILayoutSupport protocol defenition :

protocol UILayoutSupport: NSObjectProtocol {
    var length: CGFloat { get }                   //Required
    var bottomAnchor: NSLayoutYAxisAnchor { get } //Required
    var heightAnchor: NSLayoutDimension { get }   //Required
    var topAnchor: NSLayoutYAxisAnchor { get }    //Required
}

UIView class already conform to NSObjectProtocol , as well as already have same way declared properties bottomAnchor , heightAnchor , topAnchor . So, the question is: why with this extension

extension UIView: UILayoutSupport {
    var lenght: CGFloat {
        return bounds.size.height
    }
}

I still have error

Type 'UIView' does not conform to protocol 'UILayoutSupport'

您交换了最后两个属性字母:leng ht而不是leng th

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM