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

uilabel自适应高度

时间:2015-07-24 12:19:52      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

  NSString *str=@"// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the gamehhhhhhhhhhh看见了刚刚好hi了;会考虑换回来来了;了;两节课;绿林豪客;哈伦裤;哈伦裤;哈伦裤;好可怜;哈伦裤;哈伦裤;哈伦裤;哈伦裤;哈伦裤;好可怜;哈伦裤;好vfGfgigfigqiFGIwgggoGOGLFGGFKVMBXZVGHSDFGLAHOFHYAWOYFOAWHOGFAWOYEFOWOFOWHFOAEW可怜;.";
   
    //获取文字的rect
    NSDictionary *dact=@{NSFontAttributeName:[UIFont systemFontOfSize:17]};//17代表字体大小,默认17
    
    //
    CGRect textRect=[str boundingRectWithSize:CGSizeMake(320, 1000) options: NSStringDrawingUsesLineFragmentOrigin attributes:dact context:nil];
    
   //NSLog(@"%@",NSStringFromCGRect(textRect));
    
    
    
    UILabel *label=[[UILabel alloc]init];
    label.frame=CGRectMake(0,22, 320, 20);
    //label.frame.size.height=textRect.size.height;//frame中的值不可以单独修改(不可以这样)
    CGRect tempRect=label.frame;
    //单独修改高之后,再用tempRect给frame赋值
    tempRect.size.height=textRect.size.height;//用上面计算好的高付给需要修改的高
    label.frame=tempRect;
    
    
    
    label.text=str;
    //label.backgroundColor=[UIColor redColor];
    label.numberOfLines=0;
    [self.window addSubview:label];
   
    

uilabel自适应高度

标签:

原文地址:http://www.cnblogs.com/-ios/p/4672798.html

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