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。

    查看全文
  • 相关阅读:
    实验二
    实验一
    网络对抗技术 实验四 恶意代码技术
    网络对抗技术 实验三 密码破解技术
    网络对抗技术 实验二 网络嗅探与欺骗
    网络对抗技术 实验一 网络侦查与网络扫描
    实验6
    实验5
    caogao
    实验四
  • 原文地址:https://www.cnblogs.com/wangmars/p/5729716.html
  • 最新文章
  • 抽奖礼盒
    python题
    POJ 1502
    POJ 1847
    POJ 2502
    double类型的memset 填充
    POJ 1511
    POJ 3268
    POJ 2253
    POJ 2387
  • 热门文章
  • POJ 1797
    HDU1024-最大子段和
    wewcw
    实验四——恶意代码技术
    实验三—密码破解技术
    网络对抗技术实验二
    实验六
    实验五
    实验四
    实验三
Copyright © 2011-2022 走看看