xcode 使用用户定义的运行时属性的 UILabel 的cornerRadius 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42152679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cornerRadius for UILabel using User Defined Runtime Attributes not working
提问by Forte Zhu
I try to add cornerRadius to UILabel using User Defined Runtime Attributes
But it is not working as expected, cornerRadius is not setting and I wonder where I made mistake. I attached screenshot of it,
我尝试使用添加cornerRadius到UILabelUser Defined Runtime Attributes
但它没有按预期工作,cornerRadius没有设置,我想知道我在哪里犯了错误。我附上了它的截图,
Help me out in solving
帮我解决
回答by Nirav D
回答by Yogesh Makwana
回答by Ahmed Sahib
Create a category of UIView
In .h file
///Below interface
@property (nonatomic) IBInspectable UIColor *borderColor;
@property (nonatomic) IBInspectable CGFloat borderWidth;
@property (nonatomic) IBInspectable CGFloat cornerRadius;
In .m file
//below Implementation
@dynamic borderColor,borderWidth,cornerRadius;
-(void)setBorderColor:(UIColor *)borderColor{
[self.layer setBorderColor:borderColor.CGColor];
}
-(void)setBorderWidth:(CGFloat)borderWidth{
[self.layer setBorderWidth:borderWidth];
}
-(void)setCornerRadius:(CGFloat)cornerRadius{
[self.layer setCornerRadius:cornerRadius];
}
//Now you can set if from the Attribute Inspector
//现在您可以从属性检查器中设置是否