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⃣️:
     
  • 相关阅读:
    让Visual Studio 2008 和 2010支持Web Services Enhancements (WSE) 3.0
    不清楚BA的角色是什么
    int的一点事,读《深入C#内存管理来分析值类型&引用类型,装箱&拆箱,堆栈几个概念组合之间的区别》
    Angular2.0视频教程来了!
    [11]缺少动态连接库.socannot open shared object file: No such file or directory
    计算机网络常考知识点总结
    计算机网络——数据链路层
    计算机网络——物理层
    Java内存模型_基础
    JAVA_Lock
  • 原文地址:https://www.cnblogs.com/sharkHZ/p/4984108.html
Copyright © 2011-2022 走看看