UIImage *cover_bg_image = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cover_bg" ofType:@"png"]];
UIImageView *backgrdImageView_ = [[UIImageView alloc]initWithImage:cover_bg_image];
backgrdImageView_.contentMode = UIViewContentModeScaleAspectFill;
backgrdImageView_.clipsToBounds = YES;
cell.backgroundView = backgrdImageView_;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentOffset.y <= 0) {
CGFloat newHeight = COVER_CELL_HEIGHT - scrollView.contentOffset.y;
if (!(newHeight > 320))
{
NSIndexPath *indexpath_ = [NSIndexPath indexPathForRow:0 inSection:0];
UITableViewCell *coverCell_ = [self.tableView cellForRowAtIndexPath:indexpath_];
[coverCell_ setFrame:CGRectMake(coverCell_.frame.origin.x, scrollView.contentOffset.y, 320, newHeight)];
}
}
}
主要利用UIView的两个属性 UIViewContentModeScaleAspectFill, clipsToBounds.