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)容合作請聯(lián)系作者
  • 序言:七十年代末拐袜,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子章鲤,更是在濱河造成了極大的恐慌,老刑警劉巖跟束,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件勇皇,死亡現(xiàn)場離奇詭異向族,居然都是意外死亡,警方通過查閱死者的電腦和手機窘面,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進店門翠语,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人财边,你說我怎么就攤上這事肌括。” “怎么了酣难?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵谍夭,是天一觀的道長。 經(jīng)常有香客問我憨募,道長紧索,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任菜谣,我火速辦了婚禮珠漂,結(jié)果婚禮上晚缩,老公的妹妹穿的比我還像新娘。我一直安慰自己媳危,他們只是感情好荞彼,可當我...
    茶點故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著待笑,像睡著了一般鸣皂。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上暮蹂,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天寞缝,我揣著相機與錄音,去河邊找鬼仰泻。 笑死荆陆,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的我纪。 我是一名探鬼主播慎宾,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼丐吓,長吁一口氣:“原來是場噩夢啊……” “哼浅悉!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起券犁,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤术健,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后粘衬,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體荞估,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年稚新,在試婚紗的時候發(fā)現(xiàn)自己被綠了勘伺。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡褂删,死狀恐怖飞醉,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情屯阀,我是刑警寧澤缅帘,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站难衰,受9級特大地震影響钦无,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜盖袭,卻給世界環(huán)境...
    茶點故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一失暂、第九天 我趴在偏房一處隱蔽的房頂上張望彼宠。 院中可真熱鬧,春花似錦趣席、人聲如沸兵志。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽想罕。三九已至,卻和暖如春霉涨,著一層夾襖步出監(jiān)牢的瞬間按价,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工笙瑟, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留楼镐,地道東北人。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓往枷,卻偏偏與公主長得像框产,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子错洁,可洞房花燭夜當晚...
    茶點故事閱讀 44,941評論 2 355

推薦閱讀更多精彩內(nèi)容