文字高度的适配

文字高度的适配  

 

 一、单行适配, 根据字体得到NSString的尺寸

    CGSize size = [firstStr sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName,nil]];

    self.firstColumnLabel.frame = CGRectMake(80,0, size.width,size.height);

    

    CGSize Twosize = [secondStr sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName,nil]];

    self.secondColumnLabel.frame=CGRectMake(360, 0, Twosize.width, Twosize.height);

 

 

 二、多行显示,计算高度

 

    _label6.numberOfLines = 0;//把需要获取长度的lable行数设置为0

 

    CGSize lblSize = [_label6.text boundingRectWithSize:CGSizeMake(690, MAXFLOAT)options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil].size;

    _label6.frame = CGRectMake(10, 30, lblSize.width, lblSize.height);

posted @ 2017-11-10 14:59  温水青蛙。  阅读(163)  评论(0编辑  收藏  举报