码迷,mamicode.com
首页 > 其他好文 > 详细

内容自适应UILabel

时间:2014-10-25 21:21:25      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   sp   div   

xcode 6.1

File-New-Project..

iOs-Application-Simple View Application

bubuko.com,布布扣

代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UILabel *labelLoginname = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
    //[labelLoginname setNumberOfLines:0];
    NSString *s = @"账号:";
    UIFont *font = [UIFont fontWithName:@"Arial" size:15];
    CGSize size = CGSizeMake(0,0);

    NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:15]};
    CGSize labelsize = [s boundingRectWithSize:size options: NSStringDrawingUsesFontLeading  attributes:attribute context:nil].size;
    
    labelLoginname.frame = CGRectMake(80.0, 80.0, labelsize.width, labelsize.height);
    labelLoginname.backgroundColor = [UIColor whiteColor];
    labelLoginname.textColor = [UIColor blackColor];
    labelLoginname.text = s;
    labelLoginname.font = font;
    
    [self.view addSubview:labelLoginname];
}

 

内容自适应UILabel

标签:style   blog   http   color   io   os   ar   sp   div   

原文地址:http://www.cnblogs.com/jiduoduo/p/4050865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!