iOS UILabel 设置行高

发布时间:2020-06-15 19:21:09 作者:大头狼小鬼
来源:网络 阅读:474

UILabel *tileLabel = [[UILabel alloc] init];

    tileLabel.numberOfLines = 0;

    tileLabel.backgroundColor = [UIColor clearColor];

    tileLabel.text = @"调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头调整行间距云头";

    tileLabel.font = [UIFont systemFontOfSize:11.0f];

    tileLabel.textColor = [Tools colorWithHex:0x787878];


    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:tileLabel.text];

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

    [paragraphStyle setLineSpacing:18];//调整行间距

    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [tileLabel.text length])];

    tileLabel.attributedText = attributedString;


    NSDictionary *attributes = @{NSFontAttributeName:tileLabel.font, NSParagraphStyleAttributeName:paragraphStyle.copy};

    CGFloat height = [tileLabel.text boundingRectWithSize:CGSizeMake(self.view.width-32, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size.height ;

//    CGFloat height =[self changeStationWidth:tileLabel.text anWidthTxtt:self.view.width-32 anfont:11];

    tileLabel.frame = CGRectMake(16, 0, self.view.width-32, height);


    [self.view addSubview:tileLabel];


推荐阅读:
  1. iOS UILabel设置行高代码解析
  2. ios   UILabel

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

ios la uilabe

上一篇:企业使用云桌面的六大驱动力

下一篇:Hadoop Secondarynamenode原理

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》