zoukankan      html  css  js  c++  java
  • UITableView的自定义cell

    1  初始化 cell的方法中

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;

    其内部控件的frame给CGRectZero

    并且将cell内部的控件添加到 self.contentView 上面

    2 重写布局方法

    - (void)layoutSubviews;

    内部一定要执行父类的方法

    [super layoutSubviews];

    内部写控件的frame值

    3 关于模型可以写在cell内部,声明为属性,方便使用

    但是 要重写setter方法:

    - (void)setStudent:(Student *)student{

        if (_student != student) {

            [_student release];

            _student = [student retain];

            

            _headerImageView.image = [UIImage imageNamed:_student.icon];

            _nameLable.text = _student.name;

            _phoneLable.text = _student.phoneNumber;

            _introduceLable.text = _student.introduce;

        }

    }

    4 cell内部可以声明类方法:

    根据字符串的长度 求文本的高度 

    + (CGFloat)heightForString:(NSString *)string{

        NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17],NSFontAttributeName, nil]; nsfontattributename

        CGRect rect = [string boundingRectWithSize:CGSizeMake(3 * kImageWidth, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

        return rect.size.height;

    }//类方法

  • 相关阅读:
    Postman安装与使用
    最新的爬虫工具requests-html
    从高级测试到测试开发
    uiautomator2 使用Python测试 Android应用
    zalenium 应用
    Docker Selenium
    Java 测试驱动开发--“井字游戏” 游戏实战
    DevOps/TestOps概念
    Android测试(四):Instrumented 单元测试
    appium对博客园APP进行自动化测试
  • 原文地址:https://www.cnblogs.com/jiurong001/p/5186031.html
Copyright © 2011-2022 走看看