簡體   English   中英

使用用戶定義的運行時屬性的 UILabel 的cornerRadius 不起作用

[英]cornerRadius for UILabel using User Defined Runtime Attributes not working

我嘗試使用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];
}

//現在你可以從屬性檢查器中設置 if

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM