圖片下拉放大

//-----------------------------ViewController.m----------------------

#import "ViewController.h"#import "MyTableViewCell.h"#import "HFStretchableTableHeaderView.h"@interface ViewController (){

UITableView *_tableView;

NSMutableArray *dataArr;

}

@property(nonatomic,strong)NSDictionary *dic;

@property (nonatomic,strong)HFStretchableTableHeaderView *stretchHeaderView;

#define StretchHeaderHeight 200

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// 初始化表格

_tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];

// 設(shè)置代理

_tableView.delegate = self;

_tableView.dataSource = self;

// 添加到視圖上

[self.view addSubview:_tableView];

[self initStretchHeader];

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

dataArr = [[NSMutableArray alloc]initWithContentsOfFile:plistPath];

NSLog(@"%@",dataArr);//直接打印數(shù)據(jù)

}

- (void)initStretchHeader

{

//背景

UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, StretchHeaderHeight)];

bgImageView.contentMode = UIViewContentModeScaleAspectFill;

bgImageView.clipsToBounds = YES;

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

//背景之上的內(nèi)容

UIView *contentView = [[UIView alloc] initWithFrame:bgImageView.bounds];

contentView.backgroundColor = [UIColor clearColor];

self.stretchHeaderView = [HFStretchableTableHeaderView new];

[self.stretchHeaderView stretchHeaderForTableView:_tableView withView:bgImageView subViews:contentView];

}

#pragma -

#pragma mark - UITableViewDelegate表格的代理

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 200;

}

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

{

return dataArr.count;

}

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

{

static NSString *identifier = @"cell";

MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (!cell) {

cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];

}

NSDictionary *dic = dataArr[indexPath.row];

[dic objectForKey:@"content"];

NSLog(@"________%@",dic);

cell.lab1.text = [dic objectForKey:@"nickname"];

cell.lab2.text = [dic objectForKey:@"content"];

cell.img1.image = [UIImage imageNamed:[dic objectForKey:@"headImg"]];

cell.img2.image = [UIImage imageNamed:[dic objectForKey:@"headImg"]];

if (indexPath.row == 0) {

cell.img2.image = nil;

}

return cell;

}

#pragma mark - stretchableTable delegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

[self.stretchHeaderView scrollViewDidScroll:scrollView];

}

- (void)viewDidLayoutSubviews

{

[self.stretchHeaderView resizeView];

}

@end

//-----------------MyTableViewCell.h------------------------

#import@interface MyTableViewCell : UITableViewCell

@property(nonatomic,strong)UILabel *lab1,*lab2;

@property(nonatomic,strong)UIImageView *img1,*img2;

@end

//-----------------MyTableViewCell.m-----------------------

#import "MyTableViewCell.h"

@implementation MyTableViewCell

- (UILabel *)lab1{

if (!_lab1) {

_lab1 = [[UILabel alloc]initWithFrame:CGRectMake(60, 22, 200, 12)];

[self addSubview:_lab1];

}

return _lab1;

}

- (UILabel *)lab2{

if (!_lab2) {

_lab2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 72, 400, 24)];

[self addSubview:_lab2];

}

return _lab2;

}

- (UIImageView *)img1{

if (!_img1) {

_img1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 40, 40)];

[_img1.layer setCornerRadius:40/2];

_img1.layer.masksToBounds = YES ;

[self addSubview:_img1];

}

return _img1;

}

- (UIImageView *)img2{

if (!_img2) {

_img2 = [[UIImageView alloc]initWithFrame:CGRectMake(100, 112, 200, 80)];

[self addSubview:_img2];

}

return _img2;

}

@end

最后編輯于
?著作權(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)容

  • *7月8日上午 N:Block :跟一個(gè)函數(shù)塊差不多,會(huì)對(duì)里面所有的內(nèi)容的引用計(jì)數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,751評(píng)論 1 14
  • 概述在iOS開(kāi)發(fā)中UITableView可以說(shuō)是使用最廣泛的控件,我們平時(shí)使用的軟件中到處都可以看到它的影子,類(lèi)似...
    liudhkk閱讀 9,307評(píng)論 3 38
  • /*最近做了一個(gè)項(xiàng)目,項(xiàng)目中的詳情頁(yè)的效果比較單一,所以想實(shí)現(xiàn)類(lèi)似淘寶,HIGO那樣的效果.滑動(dòng)詳情和頂部圖片欄的...
    直男小金魚(yú)閱讀 864評(píng)論 0 0
  • 有一次快下班了公司還有快遞要發(fā),打電話給快遞小哥。 他說(shuō)他正在某處打包挺忙的讓我自己過(guò)去,我顧不上穿外套就直接過(guò)去...
    久懷慕藺閱讀 328評(píng)論 0 1
  • ■文/從前慢 我們隊(duì)上傻子不多,他們說(shuō)纏牢叔算我一個(gè),三十五歲那年他還光棍一個(gè),而那已經(jīng)是十幾年前的事了。 傻人可...
    從前慢者閱讀 505評(píng)論 0 2

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