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。

    查看全文
  • 相关阅读:
    初学maven五节
    Nexus如何上传自己的jar包 (upload artifactory)
    通过maven获得开源项目simple4依赖jar包的几种具体操作
    maven系列笔记(安装、下载jar、搭建私服)
    如何 提高企业网站大数据量 效率
    maven archetype:generate 的进一步理解
    为什么 Git 比 SVN 好
    使用仓库管理器——Sonatype Nexus的九大理由
    IT项目管理工具探讨之_项目群管理
    MAVEN准备建立自己的开发环境
  • 原文地址:https://www.cnblogs.com/wangmars/p/5729716.html
  • 最新文章
  • Linux expr 命令详解
    linux 下查看 hex 文件
    setbuf 函数 设置流的缓冲区
    busybox ash 对字符串操作范例
    tr 命令 (字符替换,大小写替换) linux命令五分钟系列之二十五
    Linux 自检和 SystemTap (强大的内核调试工具)
    printf的格式控制的完整格式
    linux C 字符串转换
    将换行 替换为指定字符 shell
    sysconf()函数应用举例:查看CPU及内存信息
  • 热门文章
  • Business letter writing phrases
    用wget递归下载
    initramfs实作
    Kernel Modules and System Calls
    Linux下WiFi配置工具
    某系统root filesystem挂载和init学习
    THE HEART SUTRA《般若波罗蜜多心经》英文版 by Edward Conze
    关于root、RAID、LVM
    busybox里的init
    二进制文件比较和查看
Copyright © 2011-2022 走看看