Change UIButton BorderColor in Storyboard

后端 未结 7 1294
南笙
南笙 2020-12-12 14:31

I Set CornerRadius and BorderWidth for UIbutton in User Defined Runtime Attributes. Without adding layer.borderColor it works Well and Display border in bla

相关标签:
7条回答
  • 2020-12-12 15:36

    The explanation, perhaps being lost in some of the other answers here:

    The reason that this property is not being set is that layer.borderColor needs a value with type CGColor.

    But only UIColor types can be set via Interface Builder's User Defined Runtime Attributes!

    So, you must set a UIColor to a proxy property via Interface Builder, then intercept that call to set the equivalent CGColor to the layer.borderColor property.

    This can be accomplished by creating a Category on CALayer, setting the Key Path to a unique new "property" (borderColorFromUIColor), and in the category overriding the corresponding setter (setBorderColorFromUIColor:).

    0 讨论(0)
提交回复
热议问题