Interface Builder剪切可设计视图

时间:2014-11-29 21:55:11

标签: ios xcode interface-builder rendering ibdesignable

我真的需要一只手。我创建了一个UIBabel的@IBDesignable子类,它可以在XCode Interface Builder中正常工作。但是,即使我设置了'clipBoBounds'如果为false,Interface Builder仍会剪切它,同时更改@IBInspectable属性。

如果我在模拟器或设备上运行该应用程序,则UILabel不会被剪裁并提供所需的结果(同时仍然应用Interface Builder所具有的值)。

更改前(子视图可见) Before the change

在界面建筑师的变化之后(子视图不在视野范围内) After the change (builder)

模拟器更改后(子视图符合预期) After the change (simulator)

任何帮助都会受到大力赞赏。自定义类的代码如下。

@IBDesignable class UIFeaturedLabel: UILabel {

@IBInspectable var borderWidth: Float = 4
@IBInspectable var borderOffsetX: Float = 15
@IBInspectable var borderOffsetY: Float = 5
@IBInspectable var borderColor: UIColor = UIColor.whiteColor()

private var headerView:UIView!
private var footerView:UIView!

override init() {
    super.init()
    createViews()
}

required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    createViews()
}

override init(frame: CGRect) {
    super.init(frame: frame)
    createViews()
}

func createViews() {
    clipsToBounds = false
    layer.masksToBounds = false

    headerView = UIView()
    footerView = UIView()

    headerView.backgroundColor = UIColor.whiteColor()
    footerView.backgroundColor = UIColor.whiteColor()

    addSubview(headerView)
    addSubview(footerView)
}

override func layoutSubviews() {
    super.layoutSubviews()

    let left = CGFloat( -borderOffsetX )
    let right = CGFloat( frame.width + CGFloat(borderOffsetX*2) )
    let top = CGFloat( -borderOffsetY )
    let bottom = CGFloat( frame.height - CGFloat(borderWidth/2) ) + CGFloat( borderOffsetY )

    headerView.frame = CGRectMake(left, top, right, CGFloat(borderWidth))
    footerView.frame = CGRectMake(left, bottom, right, CGFloat(borderWidth))
}
}

1 个答案:

答案 0 :(得分:2)

仍然出现在XCode 7.3 iOS9.3中,但已在XCode Version 8.0 beta(8S128d)中修复。