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

IOS UILabel自动换行

时间:2015-04-08 12:30:06      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

 {
            UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(offset_xx, offset_yy, 0, 0)];
            [lb setText:@"fawfwefwaefaewwewaefewafwefawefawefawefwaefwaefawefawefawefawafewfawefawfweafwaefawefawefawfewafawefawfawfweafwafawefwaefawefwaefaweewafwefawefawefawefwaefwaefaewafwefawefawefawefwaefwaefaewafwefawefawefawefwaefwaefaewafwefawefawefawefwaefwaefaewafwefawefawefawefwaefwaefa"];
            [lb setTextColor:[UIColor grayColor]];
            [lb setNumberOfLines:0];
            
            UIFont *font=[UIFont systemFontOfSize:13];
            [lb setFont:font];
            //设置行高上限
            CGSize size=CGSizeMake(320, 4000);
            
            //计算frame的高度
            CGRect lb_size=[lb.text boundingRectWithSize:size
                                                 options:NSStringDrawingUsesLineFragmentOrigin
                                              attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil] context:nil];
            [lb setFrame:lb_size];
            [sv addSubview:lb];
        }

 

IOS UILabel自动换行

标签:

原文地址:http://www.cnblogs.com/niit-soft-518/p/4401806.html

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