The room

#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文件


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容