图片下拉放大

//-----------------------------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];

// 设置代理

_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);//直接打印数据

}

- (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"];

//背景之上的内容

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,317评论 1 14
  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 12,958评论 3 38
  • /*最近做了一个项目,项目中的详情页的效果比较单一,所以想实现类似淘宝,HIGO那样的效果.滑动详情和顶部图片栏的...
    直男小金鱼阅读 4,162评论 0 0
  • 有一次快下班了公司还有快递要发,打电话给快递小哥。 他说他正在某处打包挺忙的让我自己过去,我顾不上穿外套就直接过去...
    久怀慕蔺阅读 1,625评论 0 1
  • ■文/从前慢 我们队上傻子不多,他们说缠牢叔算我一个,三十五岁那年他还光棍一个,而那已经是十几年前的事了。 傻人可...
    从前慢者阅读 3,308评论 0 2