實現(xiàn)效果如下:

1、定義宏,在定義位置時候方便簡潔
// 定義整個屏幕的寬、高的宏
#define S_Width [UIScreen mainScreen].bounds.size.width
#define S_Height [UIScreen mainScreen].bounds.size.height
2、創(chuàng)建需要用的滑動條和滾動視圖,并進行互相關聯(lián)
// 定義需要用的ScrollView和滑動條
@property(nonatomic,strong)UIView *lineView;
@property(nonatomic,strong)UIScrollView *bigScrollView;
// ?創(chuàng)建按鈕
-(void)createTopButton{
? ? NSArray *arr = @[@"第一頁",@"第二頁",@"第三頁"];
? ? _lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 64+50, S_Width / 3.0, 2)];
? ? _lineView.backgroundColor = [UIColor orangeColor];
? ? [self.view addSubview:_lineView];
? ? for(inti =0; i < arr.count; i++) {
? ? ? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
? ? ? ? btn.frame=CGRectMake(S_Width/3.0* i ,64,S_Width/3.0,50);
? ? ? ? [self.viewaddSubview:btn];
? ? ? ? [btnsetTitle:arr[i] forState:UIControlStateNormal];
? ? ? ? [btnaddTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
? ? ? ? btn.tag=20+i;
? ? ? ? if(i ==0) {
? ? ? ? ? ? [btnsetTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
? ? ? ? }
? ? }
}
-(void)click:(UIButton*)btn{
? ? // btn的標題:
? ? for(inti =0; i <3; i++ ) {
? ? ? ? UIButton*newBtn = [self.viewviewWithTag:20+i];
? ? ? ? if(newBtn.tag== btn.tag) {
? ? ? ? ? ? [newBtnsetTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
? ? ? ? }else{
? ? ? ? ? ? [newBtnsetTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
? ? ? ? }
? ? }
? ? // 條
? ? _lineView.frame=CGRectMake((btn.tag-20)*S_Width/3.0,64+50,S_Width/3.0,2);
? ? // ScrollView
? ? [_bigScrollView setContentOffset:CGPointMake((btn.tag - 20)*S_Width, 0)];
}
-(void)createScrollView{
? ? // 創(chuàng)建滾動視圖
? ? UIScrollView*bigScrollView = [[UIScrollViewalloc]initWithFrame:CGRectMake(0,64+52,S_Width,S_Height-64-52)];
? ? _bigScrollView= bigScrollView;
? ? bigScrollView.backgroundColor= [UIColorwhiteColor];
? ? [self.viewaddSubview:bigScrollView];
? ? bigScrollView.delegate=self;
? ? bigScrollView.tag=10;
? ? bigScrollView.contentSize=CGSizeMake(S_Width*3,0);
? ? bigScrollView.pagingEnabled=YES;
}
-(void)scrollViewDidScroll:(UIScrollView*)scrollView{
? ? CGFloatview_x =(scrollView.contentOffset.x/S_Width);
? ? // 條:
? ? _lineView.frame=CGRectMake(view_x*S_Width/3.0,64+50,S_Width/3.0,2);
? ? for(inti =0; i <3; i++ ) {
? ? ? ? UIButton*newBtn = [self.viewviewWithTag:20+i];
? ? ? ? if(newBtn.tag? -20== view_x) {
? ? ? ? ? ? [newBtnsetTitleColor:[UIColor redColor] forState:UIControlStateNormal];
? ? ? ? }else{
? ? ? ? ? ? [newBtnsetTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
? ? ? ? }
? ? }
}
-(void)createTableView{
? ? for(inti =0; i <3; i++) {
? ? ? ? UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(S_Width * i ,0, S_Width, _bigScrollView.bounds.size.height) style:UITableViewStylePlain];
? ? ? ? [tableViewregisterClass:[FirstTableViewCell class] forCellReuseIdentifier:@"FirstTableViewCell"];
? ? ? ? tableView.delegate=self;
? ? ? ? tableView.dataSource=self;
? ? ? ? [_bigScrollViewaddSubview:tableView];
? ? }
}
#pragma mark - UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
? ? return 1;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
? ? return 20;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
? ? FirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstTableViewCell"];
? ? returncell;
}