zoukankan      html  css  js  c++  java
  • 自适应UITableView的Cell高度问题

    1.自己计算Cell的高度返回:

    1>model中计算:

    //
    //  InfoModel.h
    //  OCDemo
    //
    //  Created by 思 彭 on 16/12/27.
    //  Copyright © 2016年 思 彭. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    
    @interface InfoModel : NSObject
    
    @property (nonatomic, copy) NSString *uid;
    @property (nonatomic, copy) NSString *title;
    @property (nonatomic, copy) NSString *desc;
    @property (nonatomic, copy) NSString *headImage;
    
    @property (nonatomic, assign) CGFloat cellHeight;
    
    - (instancetype)initWithDictionary: (NSDictionary *)dic;
    
    @end
    //
    //  InfoModel.m
    //  OCDemo
    //
    //  Created by 思 彭 on 16/12/27.
    //  Copyright © 2016年 思 彭. All rights reserved.
    //
    
    #import "InfoModel.h"
    
    @implementation InfoModel
    
    - (instancetype)initWithDictionary: (NSDictionary *)dic {
        
        if (self = [super init]) {
            
            self.title = dic[@"title"];
            self.headImage = dic[@"img"];
            self.desc = dic[@"desc"];
            
            CGSize contentSize = [self.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - 20, 10000000) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:15]} context:nil].size;
            self.cellHeight = contentSize.height + 74;
        }
        return self;
    }
    
    @end

    2.自定义CellFrame类存储Cell高度:

    //
    //  CellFrame.h
    //  OCDemo
    //
    //  Created by 思 彭 on 16/12/28.
    //  Copyright © 2016年 思 彭. All rights reserved.
    //
    
    #import <Foundation/Foundation.h>
    #import "InfoModel.h"
    
    @interface CellFrame : NSObject
    
    @property (nonatomic, assign) CGRect headImgViewFrame;
    @property (nonatomic, assign) CGRect titleLabelFrame;
    @property (nonatomic, assign) CGRect contentlabelFrame;
    @property (nonatomic, assign) CGFloat cellHeight;
    
    @property (nonatomic, strong) InfoModel *model;
    
    @end
    //
    //  CellFrame.m
    //  OCDemo
    //
    //  Created by 思 彭 on 16/12/28.
    //  Copyright © 2016年 思 彭. All rights reserved.
    //
    
    #import "CellFrame.h"
    
    @implementation CellFrame
    
    - (void)setModel:(InfoModel *)model {
        
        _model = model;
        _headImgViewFrame = CGRectMake(10, 10, 50, 50);
        CGSize contentSize = [model.desc boundingRectWithSize:CGSizeMake(K_SCREEN_WIDTH - 20, 10000000) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:15]} context:nil].size;
        _titleLabelFrame = CGRectMake(CGRectGetMaxX(_headImgViewFrame) + 10, 10, K_SCREEN_WIDTH - 50 - 20, 30);
        _contentlabelFrame = CGRectMake(10, CGRectGetMaxY(_headImgViewFrame) + 10, K_SCREEN_WIDTH - 20, contentSize.height);
        _cellHeight = CGRectGetMaxY(_contentlabelFrame);
    }
    
    @end

    2.使用第三方Masonry自使用行高:

    很方便,要求自己把约束要设置完全!!!

  • 相关阅读:
    ABB机器人的安全板短接详情
    基恩士HMI的跳转
    ABB 轴配置的使用(为什么需要关闭)
    ABB选项讲解
    法那科夹具夹取和放置的操作
    roboguide的夹具制作
    法那科机器人的基本介绍(创建文件)
    关于三菱触摸屏GT Designer3 仿真软件创建工程
    动态循环插入<option>,鼠标点击从数据库调取data
    ajax将众多行数组转json传入html页面循环传入table中
  • 原文地址:https://www.cnblogs.com/pengsi/p/6229821.html
Copyright © 2011-2022 走看看