zoukankan      html  css  js  c++  java
  • IOS UILabel 根据内容自适应高度

    iOS Label 自适应高度  适配iOS7以后的版本

    更多

        self.contentLabelView = [[UILabel alloc] init];

        self.contentLabelView.font = SYS_FONT(15);

        self.contentLabelView.lineBreakMode =NSLineBreakByTruncatingTail ;

        self.contentLabelView.textColor =  [UIColor colorWithHexString:@"#444444"];

        self.contentLabelView.text =[@"12312312312312321321dddsdadsadasdasdas" stringByAppendingString:@" "];

        [self.contentLabelView setNumberOfLines:0];

        

        //根据内容计算出label所需要的高度

        CGSize size = CGSizeMake(kScreenWidth - expectSizes.width-20, MAXFLOAT);

        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:self.contentLabelView.font,NSFontAttributeName,nil];

        CGSize  actualsize =[self.contentLabelView.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin  attributes:tdic context:nil].size;

        self.contentLabelView.frame =CGRectMake(expectSizes.width+20, 254, actualsize.width, actualsize.height);

     

    纯代码布局可能会用到,不过推荐使用xib或storyboard。

    查看全文
  • 相关阅读:
    (离线算法 LCA) hdu 2874
    (树形DP) hdu 4118
    (树的重心) poj 1655
    (线性基) bzoj 2115
    (线性基) bzoj 2460
    (边双联通+树直径) hdu 4612
    (拓扑图+DP) poj 3249
    (求割点和除去割点后的联通块数目) poj 1523
    (边双联通) poj 3352
    (DP求最长路) hdu 4607
  • 原文地址:https://www.cnblogs.com/wangmars/p/5729716.html
  • 最新文章
  • hdoj1013 wa(待改正)
    函数itoa
    Android开发学习之Log的使用
    Android中的依赖问题
    如何更改vue cli项目的端口
    React Loadable---自动代码拆分打开import()
    (最小生成树)hdu 3371
    (树形DP) city
    (树形DP) zoj 3626
    (树形DP) zoj 3201
  • 热门文章
  • bzoj 1045
    (树形DP) bzoj 4033
    (双指针) bzoj 1071
    (搜索) poj 3700
    (树分块) bzoj 1086
    (floyd) hdu 4034
    (基环树+DP) bzoj 1040
    (树形DP) poj 3659
    (树形DP) poj 3398
    (贪心+倍增求LCA) hdu 4912
Copyright © 2011-2022 走看看