• 自定义cell 自适应高度


    #pragma mark - 动态计算cell高度

    //计算 返回 文本高度

    + (CGFloat)calsLabelHeightWithContact:(Contacts *)contact

    {

        //size:   文字最大范围

        //options:计算高度 参数

        //  NSStringDrawingUsesLineFragmentOrigin:指定 原点 绘制字符串片段起源和基线。

        //attributes:文字某个属性 通常是大小

        //ios7 获取文本高 方法

        CGRect rect = [contact.introduce boundingRectWithSize:CGSizeMake(280, 2000)

                                                      options:NSStringDrawingUsesLineFragmentOrigin

                                                   attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17.0f] }

                                                      context:nil];

        

        return rect.size.height;

    }

    //重写contact 的setter方法

    - (void)setContact:(Contacts *)contact

    {

        if (_contact != contact) {

            [_contact release];

            _contact = [contact retain];

            

            //将获取到的值赋值到控件上,赋值

            //1,头像

            _headImageView.image = [UIImage imageNamed:contact.headImageName];

            //2,名字

            _nameLabel.text = contact.name;

            //3,电话

            _phoneNumberLabel.text = contact.phoneNumber;

            //4,性别

            _genderLabel.text = contact.gender;

            //5,年龄

            if (contact.age) {

                _ageLabel.text = contact.age;

            }else{

                _ageLabel.hidden = YES;

            }

            

            //6,简介

            _introduceLabel.text = contact.introduce;

            

            //计算高度

            CGFloat height = [BoyTableViewCell calsLabelHeightWithContact:contact];

            

            //修改高度

            CGRect frame = _introduceLabel.frame;

            frame.size.height = height;

            _introduceLabel.frame = frame;

        }

    }

    #pragma mark - 提供类方法,返回模型内容高度

    //使用模型参数,

    + (CGFloat)cellHeightWithContact:(Contacts *)contact

    {

        CGFloat h = [self calsLabelHeightWithContact:contact];

        

        return 140 + h;

    }

    //行高

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

    {

        //1,通过组索引 找出对应的key

        NSString *key = _allKeysMutaArray[indexPath.section];

        //2,通过可以 查出对应分组

        NSMutableArray *array = _allDataMutaDict[key];

        

        //3,通过row 查出 数组对应项

        Contacts *c = array[indexPath.row];

        //计算出模型的高度

        CGFloat h =[BoyTableViewCell cellHeightWithContact:c];

        

        return h;

    }

  • 相关阅读:
    How to convert VirtualBox vdi to KVM qcow2
    (OK)(OK) adb -s emulator-5554 shell
    (OK)(OK) using adb with a NAT'ed VM
    (OK) How to access a NAT guest from host with VirtualBox
    (OK) Creating manually one VMs from an existing VDI file in CLI (VBoxManage) in Fedora 23
    (OK)(OK) Creating VMs from an existing VDI file in CLI (VBoxManage) in Fedora 23
    (OK) Creating_VMs_from_an_existing_VDI_file.txt
    (OK) Creating VMs from an existing VDI file —— in OS X
    (OK) install_IBM_SERVER.txt
    (OK) install chrome & busybox in android-x86_64 —— uninstall chrome
  • 原文地址:https://www.cnblogs.com/iOS-mt/p/4187532.html
Copyright © 2020-2023  润新知