zoukankan      html  css  js  c++  java
  • 使用XIB的UITableViewCell自适应,以及出现的问题进行解决

    1.首先需要定义一个属性

    @property (nonatomic, strong) UITableViewCell *prototypeCell;

    2.在创建完tableView后加上如下代码

     self.prototypeCell=[self.tableView dequeueReusableCellWithIdentifier:CVCellId];

    3.在XIB中添加约束,此处不一一赘述


    注意的一点时在XIB中对Label设置预估值,即



    4.在heightForRowAtIndexPath中作如下修改

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        MineFixViewCell * cell=(MineFixViewCell *)self.prototypeCell;

        MineFixItem * item=[self.itemList objectAtIndex:indexPath.row];

        cell.item = item;

        CGSize size = [cell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];

        MyLog(@"%f---%f",size.width,size.height);

        return 1  + size.height;

    }

    当完成后发现一个问题,即Label中文字显示不完全,如图


    而后,在XIB中取消掉Preferred Width的勾选,而在

    awakeFromNib中添加如下代码

     self.contentLabel.preferredMaxLayoutWidth = kUIScreenWidth - 80;

    完美解决了,附图




  • 相关阅读:
    hashlib模块
    configparser模块
    xml模块和shelve模块
    json与pickle模块
    3/30
    os模块
    sys模块
    shutil模块
    random模块
    2月书单《编码隐匿在计算机软硬件背后的语言》 13-16章
  • 原文地址:https://www.cnblogs.com/melons/p/5792037.html
Copyright © 2011-2022 走看看