2014-11-29 16 views
5

Tôi thực sự cần một bàn tay ở đây. Tôi đã tạo một lớp con @IBDesignable của UILabel hoạt động tốt trong Trình tạo giao diện XCode. Tuy nhiên, ngay cả khi tôi đặt 'clipToBounds' thành false, Trình tạo giao diện sẽ vẫn cắt clip trong khi thay đổi thuộc tính @IBInspectable hoạt động.Giao diện Builder Clipping Designable Views

Nếu tôi đang chạy ứng dụng trên trình mô phỏng hoặc thiết bị, UILabel không bị cắt bớt và cho tôi kết quả mong muốn (trong khi vẫn áp dụng các giá trị mà Interface Builder có).

trước khi thay đổi (The subviews có thể nhìn thấy) Before the change

sau khi thay đổi trong giao diện Builder (The subviews là ngoài tầm nhìn) After the change (builder)

sau khi thay đổi trong mô phỏng (Các bản xem trước được mong đợi) After the change (simulator)

Mọi trợ giúp sẽ được đánh giá cao. Mã cho Lớp tùy chỉnh ở bên dưới.

@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)) 
} 
} 
+0

Tôi chỉ cần nhấn này là tốt, tôi nghĩ rằng nó là một lỗi trong Xcode. Ví dụ tối thiểu này http://stackoverflow.com/a/25475536/539149 không hoạt động trong Trình tạo giao diện như của Xcode 7.2 (7C68). –

Trả lời

2

Vẫn xảy ra với XCode 7.3 iOS9.3, nhưng được sửa trong XCode phiên bản 8.0 beta (8S128d).

Các vấn đề liên quan