I am trying to set up a view's layer properties via IB. Everything works except for color of the border (property layer.borderColor
):
I remember running into this problem a year ago and I ended up doing it programatically. And still, I can do this programmatically, but I am curious why the layer.borderColor
property never works via interface builder. I don't want to import QuartzCore
, and then write extra line of code just because of this, seems like an overkill.
In order to make CALayer KVC-compliant for the property borderColorFromUIColor, simply implement the
This link have awnser
In Swift, you can extend the
UIButton
class and add an@IBInspectable
that will enable you to select a color from storyboard and set it's color (with width of 1 which can be changed). Add this at the end of your view controller:I think it may be because you have masksToBounds set to YES. I don't think the border is drawn within the bounds of the layer, so it won't be drawn since you're hiding everything outside of its bounds.
I met the same issue, I worked around it by creating a custom button class:
Then in IB, change the type from "UIButton" to "UIButtonWithRoundBorder".
Simple and handy too. :)
swift4
borderColor
will not work UNLESS theborderWidth
property of the layer is set to a value greater than 0.Swift 3: