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(@"版本较低");

        }

  • 相关阅读:
    linux 常用快捷键
    命令行远程链接
    mybatis参数错误 Parameter '×××' not found. Available parameters are [0, 1, param1, param2]
    mybatis延迟加载
    mybatis跨XML引用
    eclipse修改项目名称
    wait, WIFEXITED, WEXITSTATUS
    进程通信中如何进行值得传递?
    fork新建进程
    Ubuntu安装genymotion模拟器步骤
  • 原文地址:https://www.cnblogs.com/jiang-xiao-yan/p/8467075.html
Copyright © 2011-2022 走看看