1 : tableview中headerview总保持在屏幕上方 : 在代理方法中创建view,并添加到headerview上
l例子:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if ([self.title isEqualToString:@"幕后"]) {
NSArray *array = @[@"全部",@"电影自习室",@"电影会客厅",@"拍摄",@"综述",@"后期",@"器材"];
UIScrollView *scroller = [[UIScrollView alloc] init];
scroller.contentSize = CGSizeMake(560, 30);
scroller.backgroundColor = [UIColor whiteColor];
scroller.showsHorizontalScrollIndicator = NO;
UISegmentedControl *segment = [[UISegmentedControl alloc] initWithItems:array];
segment.tintColor = [UIColor lightGrayColor];
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateSelected];
[scroller addSubview:segment];
return scroller;
}
return nil;
}
2 : 想随着屏幕滑动一起移动至消失的话: 就直接调用属性方法,将创建的view指定到headerview的试图()
l例子: {在viewdidload中}
self.headerView = [[HeaderView alloc] initWithFrame:CGRectMake(0, 0, 320, 150)];
self.tableView.tableHeaderView = self.headerView;