[转载]设置UITableVIew头部图片可拉伸放大的方法。
原文地址:http://blog.sina.com.cn/s/blog_8d1bc23f0102vu1q.html
// // PersonViewController.m // ChongDianZhuang // // Created by 天吴iOS - 01 on 16/5/27. // Copyright © 2016年 天吴iOS - 01. All rights reserved. // #import "PersonViewController.h" #define IMAGEHEIGHT 160 @interface PersonViewController () <UITableViewDelegate,UITableViewDataSource> { NSArray *_moreArray; UIImageView *_zoomImageView; } @end @implementation PersonViewController - (void)viewDidLoad { [super viewDidLoad]; [self onInitView]; self.view.backgroundColor = [UIColor cyanColor]; } -(void)onInitView{ UITableView *moreTableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain]; moreTableView.delegate = self; moreTableView.dataSource = self; moreTableView.contentInset = UIEdgeInsetsMake(IMAGEHEIGHT, 0, 0, 0); [self.view addSubview:moreTableView]; _zoomImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -IMAGEHEIGHT, self.view.frame.size.width, IMAGEHEIGHT)]; _zoomImageView.image = [UIImage imageNamed:@"cover.jpg"]; //_zoomImageView.backgroundColor = [UIColor yellowColor]; _zoomImageView.contentMode = UIViewContentModeScaleAspectFill; _zoomImageView.clipsToBounds = YES; [moreTableView addSubview:_zoomImageView]; if (!_moreArray) { _moreArray = [[NSArray alloc]initWithObjects:@"语言",@"体育",@"文艺",@"升学",@"职业",@"生活",@"爱好",@"1",@"2",@"3",@"4",@"5",@"6",@"7", nil]; } } #pragma mark -TableView Delegate and Datasource -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return _moreArray.count; } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 60; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell ; //static NSString *Identifier = @"Identifier"; cell =[tableView dequeueReusableCellWithIdentifier:@""]; if (cell==nil) { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil]; cell.textLabel.text = _moreArray[indexPath.row]; } return cell; } -(void)scrollViewDidScroll:(UIScrollView *)scrollView{ CGFloat y = scrollView.contentOffset.y; //如果有导航控制器,这里应该加上导航控制器的高度64 if (y< -IMAGEHEIGHT) { CGRect frame = _zoomImageView.frame; frame.origin.y = y; frame.size.height = -y; _zoomImageView.frame = frame; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end