Here is badge I need: https://github.com/jessesquires/JSCustomBadge . Works perfect!
iOS 7 UIButton alignment
Question
I'm trying to make custom badge. For that I make subclass of UIButton and remake - (void)drawRect:(CGRect)rect like this:
- (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?
Solution 2
OTHER TIPS
@property(nonatomic) NSTextAlignment textAlignment;
// default is NSTextAlignmentLeft
It's an attribute of UILabel
.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow