zoukankan      html  css  js  c++  java
  • 计算文本高度

     //计算文本的高度 commentLabel定义的成员变量

    int version=[[UIDevice currentDevice].systemVersion intValue];

        NSLog(@"当前系统的版本:%d",version);

        //评论Label的适配

        NSString *commendStr=[NSString stringWithFormat:@"%d条评论",[model.comments intValue]];

        if (version>7) {

            //根据内容的多少调整label的大小(新的API,用来替换下面的)

            CGSize size=[commendStr boundingRectWithSize:CGSizeMake(MAXFLOAT, self.commentLabel.frame.size.height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.commentLabel.font} context:nil].size;

            self.commentLabel.text=commendStr;

            self.commentLabel.frame=CGRectMake(self.commentLabel.x, self.commentLabel.y,size.width, self.commentLabel.height);

            NSLog(@"版本大于7.0");

        }else{

            //根据内容的多少调整label的大小(老的API)

            CGSize size=[commendStr sizeWithFont:_commentLabel.font constrainedToSize:CGSizeMake(MAXFLOAT, _commentLabel.frame.size.height) lineBreakMode:NSLineBreakByWordWrapping];

            _commentLabel.text=commendStr;

            _commentLabel.frame=CGRectMake(_commentLabel.x, _commentLabel.y, size.width, _commentLabel.height);

            

            NSLog(@"版本较低");

        }

  • 相关阅读:
    用javascript写星际飞机大战游戏
    Vue源码分析之实现一个简易版的Vue
    Vue源码分析之数据驱动
    Vue源码分析之虚拟DOM
    使用HbuilderX离线打包5+APP
    ERROR in build.js from UglifyJs
    PHP 的一些开发规范
    Markdown使用TOC自动生成导航栏
    Hexo博客skapp主题部署填坑指南
    Docker 官方安装详解
  • 原文地址:https://www.cnblogs.com/jiang-xiao-yan/p/8467075.html
Copyright © 2011-2022 走看看