设为首页 加入收藏

TOP

iOS--UILable自适应大小
2017-10-13 10:24:26 】 浏览:1653
Tags:iOS--UILable 适应 大小

#import "ViewController.h"

 

@interface ViewController ()

@property(strong,nonatomic) UILabel *lable;

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    [self.lable setNumberOfLines:0];

    self.lable.text=@"最近一年多,尽管交易数据靓丽,但经过一年操作后,老王发现炒房还是没有利润空间。他终于明白,房价已失去大涨的土壤环境,主要是房源库存量大,传统企业生存艰难,年轻人购房欲望减弱,资产配置转向资本市场,“炒房已经到了末日”[2006年至2011年,温州市区商品房销售均价从8045元/平方米一路上涨至34674元/平方米,5年时间涨了3倍左右。老王说,温州房价每平方米从1万元涨到2万元,花了一年多点时间;从2万元涨到3万元,只用了一年不到。][2009年,温州人均GDP仅4604美元,在浙江省排倒数第三,不到杭州的一半,也只有浙江省人均GDP的71%。]";

    self.lable.backgroundColor=[UIColor grayColor];

    // 设置段落风格

    NSMutableParagraphStyle *par=[[NSMutableParagraphStyle alloc]init];

    par.lineHeightMultiple=NSLineBreakByCharWrapping;

    // 设置段落字体风格

    NSDictionary *dic=@{NSFontAttributeName:self.lable.font,NSParagraphStyleAttributeName:par.copy};

    // 计算 lable 的实际大小  返回文本绘制的区域

    CGRect rect=[self.lable.text boundingRectWithSize:CGSizeMake(self.view.frame.size.width, self.view.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

    // 设置标签到屏幕顶端的距离

    self.lable.frame=CGRectMake(0, 70, rect.size.width, rect.size.height);

    [self.view addSubview:self.lable];

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇iOS dom解析xml格式数据 下一篇iOS开发之--HTTP请求

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目