在界面构建器中的UIView的边框颜色不工作? [英] UIView's border color in Interface builder doesn't work?
问题描述
我想通过IB设置视图的图层属性。一切正常,除了边框颜色(属性 layer.borderColor
):
I am trying to set up a view's layer properties via IB. Everything works except for color of the border (property layer.borderColor
):
我记得一年前遇到这个问题,我结束了编程。仍然,我可以通过编程,但我很好奇为什么 layer.borderColor
属性永远不能通过界面生成器工作。我不想导入 QuartzCore
,然后写出额外的代码行只是因为这,似乎是一个过度。
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.
推荐答案
这是可能的,但它不是一个内置的功能。这是因为用户定义的运行时属性面板中的 Color
类型创建了 UIColor
,但 layer.borderColor
包含 CGColorRef
类型。不幸的是,没有办法在Interface Builder中指定 CGColorRef
类型。
It's possible to do this, but it's not a built-in feature. This is because the Color
type in the User Defined Runtime Attributes panel creates a UIColor
, but layer.borderColor
holds a CGColorRef
type. Unfortunately, there's no way to assign a CGColorRef
type in Interface Builder.
但是,这可以通过代理属性。有关解决此问题的其他问题,请参阅 Peter DeWeese的回答。他的答案定义了允许通过Interface Builder设置代理颜色的类别。
However, this is possible through a proxy property. See Peter DeWeese's answer to a different question for a possible solution to this problem. His answer defines a category that allows a proxy color to be set through Interface Builder.
这篇关于在界面构建器中的UIView的边框颜色不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!