zoukankan      html  css  js  c++  java
  • 自适应高度cell

    - (instancetype)initWithFrame:(CGRect)frame {

        if (self = [super initWithFrame:frame]) {

            _onlyLabel = [[UILabel alloc] initWithFrame:CGRectZero];

            [self.contentView addSubview:_onlyLabel];

        }

        return self;

    }

     

    - (void)layoutSubviews {

        [super layoutSubviews];

        _onlyLabel.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [MyTableViewCell heightForString:self.person.name]);

    }

     

    + (CGFloat)heightForString:(NSString *)string {

        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil ];

        CGRect rect = [string boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

        return rect.size.height;

    }

     

    + (CGFloat)cellForStudent:(Person *)person {

        

        return 20 + [MyTableViewCell heightForString:person.name];

    }

  • 相关阅读:
    Python常用模块学习
    如何在cmd下切换不同版本的Python
    Python3
    Python第二模块(文件和函数)
    Hibernate教程一览
    struts2框架一览
    Java正式day_04——嵌套循环
    AJAX
    JS+JQUERY
    Mybatis注意问题
  • 原文地址:https://www.cnblogs.com/naizui/p/5211579.html
Copyright © 2011-2022 走看看