首页 > 其他 > 详细

uilabel自适应高度

时间:2015-07-24 12:19:31      阅读:239      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!