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。

    查看全文
  • 相关阅读:
    yii2.0安装redis
    composer
    Windows下安装redis
    Windows下启动redis闪退
    svn的使用及安装
    mysql主从
    linux下远程链接mysql报错1045
    git命令行克隆报错fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
    git克隆报错128
    yii phpexcel <转>
  • 原文地址:https://www.cnblogs.com/wangmars/p/5729716.html
  • 最新文章
  • Java基础系列--this、super关键字
    Java基础系列--final、finally关键字
    Java基础系列--static关键字
    Java基础系列--Executor框架(一)
    数据结构基础--线性表
    Java中的代码点和代码单元(转)
    java基础系列--volatile关键字
    SpringBoot文档翻译系列——26.日志logging
    SpringBoot文档翻译系列——29.SQL数据源
    java基础系列--集合类库(一)
  • 热门文章
  • BZOJ1970 [Ahoi2005] 矿藏编码
    BZOJ1968 [Ahoi2005] 约数研究
    BZOJ1179 [Apio2009] Atm
    BZOJ1149 [CTSC2007]风玲
    BZOJ1014 [JSOI2008]火星人
    BZOJ3994 [SDOI2015]约数个数和
    BZOJ3233 [Ahoi2013]找硬币
    BZOJ1053 [HAOI2007]反素数 & BZOJ3085 反质数加强版SAPGAP
    BZOJ2656 [Zjoi2012]数列
    redis学习基本命令
Copyright © 2011-2022 走看看