CornerRadius for UILabel using custom runtime attributes not working

I am trying to add cornerRadius to UILabel using User Defined Runtime Attributes But it does not work as expected, cornerRadius is not configurable, and I wonder where I made a mistake. I attached a screenshot to it,

enter image description here

Help me decide

+4
source share
3 answers

It is layer.cornerRadiusnot just cornerRadiusalso what you need to install layer.masksToBoundsin true.

enter image description here

+10
source

Create an extension to set the radius of the corner from the storyboard

enter image description here

public extension UIView {

    @IBInspectable public var cornerRadius: CGFloat {
        get { return layer.cornerRadius }
        set { layer.cornerRadius = newValue }
    }
}
+6
source
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];
}

// ,

+2
source

Source: https://habr.com/ru/post/1669339/


All Articles