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];

    }

  • 相关阅读:
    方法重载
    构造方法:(特殊方法,用来创建对象 没写就会默认有构造方法)
    java:第十二章
    java:第九章
    java:第十四章
    java:第十五章
    java:第十一章
    I/O小结
    java:第八章
    java:第六章
  • 原文地址:https://www.cnblogs.com/naizui/p/5211579.html
Copyright © 2011-2022 走看看