2014-07-15 29 views
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)]; 
} 

一切工作正常,但文字在我的标签显示不好,这里是我的标签截图。

enter image description here

我想是这样的。

enter image description here

请帮助和您的时间的感谢。

+1

结帐[这](http://www.jessesquires.com/JSQMessagesViewController/)和[此](https://github.com/SocialObjects-Software/SOMessaging)可能会有帮助 –

+0

我会检查你的链接,并非常帮助我的工作,非常感谢。 – vietnguyen09

回答