1、TableView的headView背景图片拉伸
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. _bgImage =[[UIImageView alloc] initWithFrame:CGRectMake(, , CScreenWidth, CScreenHeight)];
_bgImage.image = [UIImage imageNamed:@"pic4"];
orginYframe = _bgImage.frame;
[self.view addSubview:_bgImage]; _headView = [[UIView alloc] initWithFrame:CGRectMake(, , CScreenWidth, )];
_headView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:];
_titleLBel = [[UILabel alloc] init];
_titleLBel.frame =CGRectMake(, , CScreenWidth, );
_titleLBel.text = @"测试界面";
_titleLBel.textColor = [UIColor greenColor];
_titleLBel.textAlignment = NSTextAlignmentCenter;
[_headView addSubview:_titleLBel];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(addDataClick) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"back" forState:UIControlStateNormal];
[btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
btn.frame = CGRectMake(, , , );
[_headView addSubview:btn];
[self.view addSubview:_headView]; _tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , CScreenWidth, CScreenHeight-)];
UIView *headViewT = [[UIView alloc] initWithFrame:CGRectMake(, , CScreenWidth, )];
headViewT.backgroundColor = [UIColor clearColor];
_tableView.tableHeaderView = headViewT;
_tableView.delegate =self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:_tableView]; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
cell.textLabel.text =@"测试一下";
return cell;
} - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offSetY = scrollView.contentOffset.y;
NSLog(@"===%f",offSetY);
if (offSetY < )
{
_titleLBel.textColor = [UIColor blueColor];
_headView.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:offSetY/];
}
else
{
_titleLBel.textColor = [UIColor redColor];
_headView.backgroundColor = [UIColor whiteColor];
}
if (offSetY > )
{
_bgImage.frame = ({
CGRect frame = _bgImage.frame;
frame.origin.y = orginYframe.origin.y - offSetY;
frame;
});
}
else
{
_bgImage.frame = ({
CGRect frame = _bgImage.frame;
frame.size.width =orginYframe.size.width -offSetY;
frame.size.height = orginYframe.size.height *frame.size.width/ orginYframe.size.width;
frame.origin.x = -(frame.size.width - orginYframe.size.width)/;
NSLog(@"----%@",NSStringFromCGRect(frame));
frame;
});
}
if (offSetY ==)
{
_titleLBel.textColor = [UIColor redColor];
}
}