iOS --stretchTableHeader的使用
这里只是使用了一个简单的表格来实现效果
ViewController.m 代码如下
首先导入#import "HFStretchableTableHeaderView.h"
@property (nonatomic,strong)HFStretchableTableHeaderView *stretchHeaderView;
#define StretchHeaderHeight 200
[self initStretchHeader]; //在viewDidLoad中调用
- (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:@"1.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 mark - stretchableTable delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.stretchHeaderView scrollViewDidScroll:scrollView];
}
- (void)viewDidLayoutSubviews
{
[self.stretchHeaderView resizeView];
}