您的位置:首页 > 移动开发 > IOS开发

iOS中tableview中headerview总保持在屏幕上方和随着屏幕滑动一起移动至消失

2015-04-22 16:00 573 查看
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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: