使UIView类符合UILayoutSupport协议

时间:2016-08-03 08:52:33

标签: ios swift

出于某种原因,我希望将UIView个实例用作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已经符合NSObjectProtocol,并且已经使用相同的方式声明了属性bottomAnchorheightAnchortopAnchor。所以,问题是:为什么使用此扩展名

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

我仍然有错误

  

键入' UIView'不符合协议' UILayoutSupport'

1 个答案:

答案 0 :(得分:2)

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