我正在打包我每天在工作流程中使用的扩展。我在UIView上提取这个扩展并将其放入一个框架中。
我做了初始构建,所有这些IBInspectable属性在使用此框架的项目中都不可访问。下面是独立框架中的UIView扩展的代码。
public extension UIView {
@IBInspectable public var cornerRadius: CGFloat {
get {
return self.layer.cornerRadius
}
set {
self.layer.cornerRadius = newValue
}
}
@IBInspectable public var borderWidth: CGFloat {
get {
return self.layer.borderWidth
}
set {
self.layer.borderWidth = newValue
}
}
@IBInspectable public var borderColor: UIColor? {
get {
guard let borderColor = self.layer.borderColor else {
return nil
}
return UIColor(cgColor: borderColor)
}
set {
self.layer.borderColor = newValue?.cgColor
}
}
@IBInspectable public var shadowColor: UIColor? {
get {
guard let shadowColor = self.layer.shadowColor else {
return nil
}
return UIColor(cgColor: shadowColor)
}
set {
self.layer.shadowColor = newValue?.cgColor
}
}
@IBInspectable public var shadowOffset: CGSize {
get {
return self.layer.shadowOffset
}
set {
self.layer.shadowOffset = newValue
}
}
@IBInspectable public var shadowRadius: CGFloat {
get {
return self.layer.shadowRadius
}
set {
self.layer.shadowRadius = newValue
}
}
@IBInspectable public var shadowOpacity: CGFloat {
get {
return CGFloat(self.layer.shadowOpacity)
}
set {
self.layer.shadowOpacity = Float(newValue)
}
}
}有没有想过,我可能做错了什么?
发布于 2019-01-23 15:20:51
使用open而不是public作为访问说明符来访问模块外部的class和变量。
open extension UIView {
@IBInspectable open var cornerRadius: CGFloat {
get {
return self.layer.cornerRadius
}
set {
self.layer.cornerRadius = newValue
}
}https://stackoverflow.com/questions/54099407
复制相似问题