【发布时间】:2014-03-28 09:46:27
【问题描述】:
我一直在试图弄清楚如何将我的 UILabel 文本垂直对齐到顶部或底部。问题是,我后面有一个图像,它也随着文本移动。
有没有办法将背景颜色/图像保持在原位,但只能向上或向下移动文本?
这是当前代码:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (!self) return nil;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,
0,
frame.size.width,
frame.size.height)];
label.textAlignment = NSTextAlignmentLeft;
label.font = [UIFont fontWithName:@"AvenirNext-Bold" size:12];
label.backgroundColor = [UIColor clearColor];
[self addSubview:label];
self.numberLabel = label;
self.layer.cornerRadius = 3;
return self;
}
我一直在关注本教程,但它改变了一切,包括我的标签背景。 Vertically align text to top within a UILabel
【问题讨论】:
标签: ios objective-c