码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UILabel自动适应开度和高度

时间:2015-07-10 00:35:10      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

    //这个frame是初设的,没关系,后面还会重新设置其size。
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    
    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],};
    
    NSString *str = @"abcdefg你上课可是你的拿到了";
    CGSize textSize = [str boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;
    
    [label setFrame:CGRectMake(100, 100, textSize.width, textSize.height)];
    label.textColor = [UIColor greenColor];
    label.text = str;
    [self.view addSubview:label];


iOS UILabel自动适应开度和高度

标签:

原文地址:http://my.oschina.net/u/1440723/blog/476826

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