简体   繁体   English

iOS 7 UIButton对齐

[英]iOS 7 UIButton alignment

I'm trying to make custom badge. 我正在尝试制作自定义徽章。 For that I make subclass of UIButton and remake - (void)drawRect:(CGRect)rect like this: 为此,我使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;
    }

And everything is good except alignment. 除了对齐,一切都很好。 It is a little upper than it should be. 它比应有的略高。 Looks like this: 看起来像这样: 在此处输入图片说明

What to do? 该怎么办?

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

这是UILabel的属性。

Here is badge I need: https://github.com/jessesquires/JSCustomBadge . 这是我需要的徽章: https : //github.com/jessesquires/JSCustomBadge Works perfect! 完美的作品!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM