I really need a hand here. I created a subclass of @IBDesignable UILabel that works fine in the XCode Interface Builder. However, even if I set 'clipsToBounds' to false, Interface Builder will still clamp it, and changing @IBInspectable properties will work.
If I run the application on a simulator or device, UILabel does not crop and gives me the desired results (while still applying the values ββthat the Builder interface has).
BEFORE CHANGE (visible areas visible) 
AFTER CHANGE IN THE INTERFACE-BUILDER (eyeliners are out of sight) 
AFTER CHANGE IN SIMULATOR (Subsections are expected) 
Any help would be greatly appreciated. The code for the custom class is below.
@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)) } }
source share