zoukankan      html  css  js  c++  java
  • 自动调整文字高度With what should I replace the deprecated sizeWithFont:contrainedToSize:lineBreakMode method?

    自动调整文字的高度:

    ios 2.0 ~ 7.0以下:

     UILabel *orgnizationLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.cellImageView.frame.size.height + 5, self.cellImageView.frame.size.width, 0)];
            self.nameLabel = orgnizationLabel;
            self.nameLabel.text = @"富力桃园幼儿园管理员";
            self.nameLabel.textAlignment = NSTextAlignmentLeft;
            self.nameLabel.font = [UIFont systemFontOfSize:16.0];
            self.nameLabel.numberOfLines = 0;
            self.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
            self.nameLabel.textColor = [UIColor colorWithRed:68/255.0f green:153/255.0f blue:181/255.0f alpha:1.0];
            
            CGRect labelFrameN = self.nameLabel.frame;
           labelFrameN.size = [self.nameLabel.text sizeWithFont:self.nameLabel.font
                                               constrainedToSize:CGSizeMake(self.nameLabel.frame.size.width, CGFLOAT_MAX)
                                                   lineBreakMode:self.nameLabel.lineBreakMode];
            self.nameLabel.frame = labelFrameN;


    7.0以及以后:

      CGRect labelFrameN = self.nameLabel.frame;

            
            NSDictionary *stringAttributes = [NSDictionary dictionaryWithObject:self.nameLabel.font forKey: NSFontAttributeName];
            
            labelFrameN.size = [self.nameLabel.text boundingRectWithSize:CGSizeMake(self.nameLabel.frame.size.width, CGFLOAT_MAX)
                                                             options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
                                                          attributes:stringAttributes context:nil].size;
            
            self.nameLabel.frame = labelFrameN;

  • 相关阅读:
    SQL SERVER列转换行及UNPIVOT
    25.元素,元素内容和元素属性 Walker
    16.开发工具介绍 Walker
    13.前后端程序浅解 Walker
    21.创建标准的html文件 Walker
    15.html和html5 Walker
    24.代码注释 Walker
    22.文档的基本结构 Walker
    23.单标签和双标签 Walker
    26.代码书写规范 Walker
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3445161.html
Copyright © 2011-2022 走看看