我将用代码
绘制UILabelCustomLabel *label = [[CustomLabel alloc] initWithFrame:CGRectMake(0, 0, 260, 100)];
label.layer.borderColor = [[UIColor redColor] CGColor];
label.layer.borderWidth = 3.0;
[label setFont:[UIFont fontWithName:@"Helvetica" size:16]];
CALayer * l1 = [label layer];
[l1 setMasksToBounds:YES];
[l1 setCornerRadius:10.0];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = NSTextAlignmentLeft; // UITextAlignmentCenter, UITextAlignmentLeft
label.textColor=[UIColor whiteColor];
label.backgroundColor = [UIColor redColor];
label.numberOfLines=4;
label.lineBreakMode=NSLineBreakByWordWrapping;
label.text = [NSString stringWithFormat:@"%@", message];
label.tag = index;
[label sizeToFit];
当然,我会从stackoverflow找到一个用于标签创建填充的解决方案 代码
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(5,5,5,5); //customize padding here
}
return self;
}
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(rect, self.edgeInsets)];
}
一切正常,但我的标签中的文字显示不好,这是我的标签截图。
我想要这样。
请帮助并感谢您的时间。