使用用户定义的运行时属性的UILabel的cornerRadius不起作用

我尝试使用User Defined Runtime Attributes将cornerRadius添加到UILabel但它没有按预期工作,cornerRadius没有设置,我想知道我在哪里犯了错误。 我附上了它的截图,

在此处输入图像描述

帮助我解决问题

它是layer.cornerRadius而不仅仅是cornerRadius你还需要将layer.masksToBounds设置为true

在此处输入图像描述

创建扩展以从故事板设置角半径

在此处输入图像描述

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

//现在您可以从属性检查器中设置是否