簡體   English   中英

iOS 7 UIButton對齊

[英]iOS 7 UIButton alignment

我正在嘗試制作自定義徽章。 為此,我使UIButton的子類並重新制作-(void)drawRect:(CGRect)rect像這樣:

    - (void)drawRect:(CGRect)rect
    {
        self.titleLabel.font = [UIFont systemFontOfSize:12];
        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.userInteractionEnabled = NO;
        self.layer.borderWidth = 1.5f;
        self.layer.cornerRadius = rect.size.width / 2;
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [[UIScreen mainScreen] scale];
        self.layer.backgroundColor = [UIColor grayColor].CGColor;
        self.layer.borderColor = [UIColor grayColor].CGColor;
    }

除了對齊,一切都很好。 它比應有的略高。 看起來像這樣: 在此處輸入圖片說明

該怎么辦?

@property(nonatomic) NSTextAlignment textAlignment;
// default is NSTextAlignmentLeft

這是UILabel的屬性。

這是我需要的徽章: https : //github.com/jessesquires/JSCustomBadge 完美的作品!

暫無
暫無

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

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