这是我的@IBInspectable:
代码:
@IBDesignable
class PBOView: UIView {
@IBInspectable var borderRightColor: UIColor? {
didSet {
let borderRightView = UIView(frame: CGRectMake(frame.size.width - 10, 0, 10, frame.size.height))
borderRightView.backgroundColor = borderRightColor
addSubview(borderRightView)
}
}
}
这是 Storyboard 中的结果:
UIView 的宽度是150
在 iPhone 模拟器中:
UIView 的宽度是150
,但应该是80
因为它是 iPhone。这就是为什么在我的自定义视图中看不到矩形的原因
当我设置clearColor
为视图的背景时,结果如下:
为什么该 UIView 的边界和框架宽度错误? 实际上它们是来自 Storyboard 的宽度,而不是运行时的真实宽度。