我正在尝试为UIButton保留边框。如果我使用下面的代码,它工作。为UIButton设置边框
案例:1
[[_myButton layer] setBorderWidth:1.0f];
[[_myButton layer] setBorderColor:[UIColor lightGrayColor].CGColor];
但在此之前,当我写:
self.baseTypeButton.layer.borderWidth=2.0f;
self.myButton.layer.borderColor=[UIColor lightGrayColor];
的XCode建议我做
现在我的代码更改,但我在这种情况下未能设置边界:
案例:2
_myButton.layer.borderWidth=2.0f;
_myButton.layer.borderColor=(__bridge CGColorRef _Nullable)([UIColor lightGrayColor]);
我没有使用自动布局。任何人都可以解释案例1和案例2有什么区别吗?为什么情况-2不会工作。
你加上'#进口'框架? –
ivarun
@ivarun:QuartzCore框架已添加到我的项目中 –
UIColor不是CGColor。你无法弥合它。你可以用这个来节省你的时间https://github.com/AlexHsieh/ButtonAppearance – AlexHsieh