The room

作者: 黑市掌柜 | 来源:发表于2017-08-24 19:14 被阅读3次

    #import "ViewController.h"

    #import "MyTableViewCell.h"

    @interface ViewController ()<UITableViewDelegate,UITableViewDataSource>{

    UITableView *table;

    UIImageView *img;

    NSArray *array;

    }

    - (void)viewDidLoad {

    table = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];

    table.rowHeight = 170;

    table.dataSource = self;

    table.delegate = self;

    [self.view addSubview:table];

    img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

    img.image = [UIImage imageNamed:@"headerImage1.jpg"];

    UIView *v1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

    table.tableHeaderView = v1;

    [v1 addSubview:img];

    UIView *v2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    table.backgroundView = v2;

    [v2 addSubview:img];

    NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"friends"  ofType:@"plist"];

    array = [[NSArray alloc] initWithContentsOfFile:plistPath];

    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return array.count;

    }

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@""];

    if (!cell) {

    cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@""];

    }

    NSMutableDictionary *dicc = array[indexPath.row];

    NSLog(@"======%@",dicc);

    cell.oneLb.text = [dicc objectForKey:@"content"];

    cell.oneImg.image = [UIImage imageNamed:[dicc objectForKey:@"headImg"]];

    cell.twoLb.text = [dicc objectForKey:@"nickname"];

    cell.twoImg.image = [UIImage imageNamed:[dicc objectForKey:@"picture"]];

    return cell;

    }

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {

    CGRect tempRect = img.frame;

    if (scrollView.contentOffset.y > 0) {

    tempRect.origin.y = -scrollView.contentOffset.y;

    img.frame = tempRect;

    }else {

    tempRect.origin.y = 0;

    tempRect.size.height = 200 - scrollView.contentOffset.y;

    img.frame = tempRect;

    }

    }

    MytableViewCell.h

    @property(nonatomic,strong)UIImageView *oneImg,*twoImg;

    @property(nonatomic,strong)UILabel *oneLb,*twoLb;

    MytableViewCell.m

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

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

    [self.contentView addSubview:self.oneImg];

    [self.contentView addSubview:self.twoImg];

    [self.contentView addSubview:self.oneLb];

    [self.contentView addSubview:self.twoLb];

    }

    return self;

    }

    -(UIImageView *)oneImg{

    if (!_oneImg) {

    _oneImg = [[UIImageView alloc]initWithFrame:CGRectMake(2, 2, 30,30)];

    _oneImg.layer.cornerRadius = 15;

    _oneImg.layer.masksToBounds = YES;

    }

    return _oneImg;

    }

    -(UIImageView *)twoImg{

    if (!_twoImg) {

    _twoImg = [[UIImageView alloc]initWithFrame:CGRectMake(100, 60, 150 ,100)];

    }

    return _twoImg;

    }

    -(UILabel *)oneLb{

    if (!_oneLb) {

    _oneLb = [[UILabel alloc]initWithFrame:CGRectMake(35, 5, 400, 20)];

    }

    return _oneLb;

    }

    -(UILabel *)twoLb{

    if (!_twoLb) {

    _twoLb = [[UILabel alloc]initWithFrame:CGRectMake(2,35, 400, 20)];

    }

    return _twoLb;

    }

    plist文件

    相关文章

      网友评论

          本文标题:The room

          本文链接:https://www.haomeiwen.com/subject/mhoedxtx.html