iOS可複用控件之分段滾動控件HTSegmentedScrollView

分段滾動頁面是一個比較常見的需求,我把我的實現方式封裝了一下,方便以後重複使用。

實現效果:


GitHub地址:https://github.com/runThor/HTSegmentedScrollView

使用方式非常簡單,添加segment的title以及添加滾動的view即可,代碼如下:

#import "HTSegmentedScrollView.h"

- (void)viewDidLoad {
    [super viewDidLoad];
    
    HTSegmentedScrollView *segView = [[HTSegmentedScrollView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [self.view addSubview:segView];
    
    [segView addSegmentedItems:@[@"紅色", @"黃色", @"藍色"]];  // 添加title
    
    UIView *redView = [[UIView alloc] init];
    redView.backgroundColor = [UIColor redColor];
    UIView *yellowView = [[UIView alloc] init];
    yellowView.backgroundColor = [UIColor yellowColor];
    UIView *blueView = [[UIView alloc] init];
    blueView.backgroundColor = [UIColor blueColor];
    
    [segView addScrollViews:@[redView, yellowView, blueView]];  // 添加滾動的view
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章