1
我會畫的UILabel與代碼如何繪製填充文字不隱藏的UILabel?
CustomLabel *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];
當然,我會發現從計算器的解決方案爲標籤 創建填充用代碼
- (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)];
}
一切工作正常,但文字在我的標籤顯示不好,這裏是我的標籤截圖。
我想是這樣的。
請幫助和您的時間的感謝。
結帳[這](http://www.jessesquires.com/JSQMessagesViewController/)和[此](https://github.com/SocialObjects-Software/SOMessaging)可能會有幫助 –
我會檢查你的鏈接,並非常幫助我的工作,非常感謝。 – vietnguyen09