cornerRadius for UILabel using User Defined Runtime Attributes not working

回眸只為那壹抹淺笑 提交于 2019-12-23 10:28:24

问题


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,

Help me out in solving


回答1:


It is layer.cornerRadius not just cornerRadius also you need to set layer.masksToBounds to true.




回答2:


Create extension to set corner radius from storyboard

public extension UIView {

    @IBInspectable public var cornerRadius: CGFloat {
        get { return layer.cornerRadius }
        set { layer.cornerRadius = newValue }
    }
}



回答3:


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



来源:https://stackoverflow.com/questions/42152679/cornerradius-for-uilabel-using-user-defined-runtime-attributes-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!