IBInspectable UIEdgeInsets not shown in IBOutlet

I am creating a custom class for UIButton to increase the scope. I need the user to be able to enter an add-on in the storyboard itself. Therefore, I create an IBInspectable property.

 @IBDesignable class UIIconButton: UIButton { @IBInspectable var touchPadding:UIEdgeInsets = UIEdgeInsetsZero } 

But he is not shown in the storyboard. However, if you replace it with CGRect , then this can be seen in the storyboard.

+7
ios xcode7 xib storyboard ibinspectable
source share
1 answer

As in Xcode 7, Interface Builder does not understand UIEdgeInsetsZero as @IBInspectable (bummer!).

You can get around this, however, by using the CGFloat properties to set indirect attachments:

 public class UIIconButton: UIButton { @IBInspectable public var bottomInset: CGFloat { get { return touchPadding.bottom } set { touchPadding.bottom = newValue } } @IBInspectable public var leftInset: CGFloat { get { return touchPadding.left } set { touchPadding.left = newValue } } @IBInspectable public var rightInset: CGFloat { get { return touchPadding.right } set { touchPadding.right = newValue } } @IBInspectable public var topInset: CGFloat { get { return touchPadding.top } set { touchPadding.top = newValue } } public var touchPadding = UIEdgeInsetsZero } 

This will correctly display bottomInset , leftInset , etc. in the interface builder.

+17
source share

All Articles