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;

    完美解决了,附图




  • 相关阅读:
    10 给予scrapy-redis的分布式爬虫
    pandas 01 序列和数据库昂
    如何控制分布式爬虫结束
    动态导入模块
    docker
    09 scrapy中间件
    scrapy 获取settings中的内容
    session对象的cookies
    文本检测-1-MSER
    CTW1500数据集介绍
  • 原文地址:https://www.cnblogs.com/melons/p/5792037.html
Copyright © 2011-2022 走看看