zoukankan      html  css  js  c++  java
  • 进击的UI------------------- Plist&自定义Cell

    1.plist
    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"name" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
    2.tableView的自定义cell
    1⃣️:cell.m
    // 自定义cell的初始化方法
    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
        if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
            [self p_setupView];
        }
        return self;
    }
    - (void)p_setupView{
        self.myImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];
    //    self.myImage.backgroundColor = [UIColor brownColor];
        // 自定义cell把控件添加到cell的contentView上面
        [self.contentView addSubview:_myImage];
        self.nameLable = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.myImage.frame) + 10, CGRectGetMinY(self.myImage.frame), CGRectGetWidth(self.contentView.frame) - CGRectGetWidth(self.myImage.frame) - 30,CGRectGetHeight(self.myImage.frame))];
        self.nameLable.backgroundColor = [UIColor brownColor];
        [self.contentView addSubview:_nameLable];
    }
    // 当bounds发生改变 走一个方法
    - (void)layoutSubviews{
        self.nameLable.frame = CGRectMake(CGRectGetMaxX(self.myImage.frame) + 10, CGRectGetMinY(self.myImage.frame), CGRectGetWidth(self.contentView.frame) - CGRectGetWidth(self.myImage.frame) - 30, CGRectGetHeight(self.myImage.frame));
    }
    2⃣️:controller.m
    - (void)viewDidLoad {
        [super viewDidLoad];
        // 1 先注册
        [self.tableView registerClass:[MyCell class] forCellReuseIdentifier:@"cell"];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        // 用自定义cell
        MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
        cell.myImage.image = [UIImage imageNamed:@"1.png"];
        cell.nameLable.text = @"宋慧乔";
        cell.nameLable.font = [UIFont systemFontOfSize:20];
        return cell;
    }
    3.cell - model
    1⃣️:
    2⃣️:
    3⃣️:
    4⃣️:
    6⃣️:
     
  • 相关阅读:
    oracle,sql server count函数 存储过程 判断 行数 注意事项
    js 跨域访问 获取验证码图片 获取header 自定义属性
    开发作中常用,实用工具推荐!
    phpcms
    php基础
    jQuery , js 写选项卡
    js, jquery实现全选,反选
    jQuery选择器
    学习jQuery
    javascript 与 java继承问题
  • 原文地址:https://www.cnblogs.com/sharkHZ/p/4984108.html
Copyright © 2011-2022 走看看