最小化分段控件,可滚动,可定制,可动,使用极其简单。
与YTPageController配合工作得很好
仅需使用界面 Builder
... 或者您更喜欢代码
WDScrollableSegmentedControl *segmentedControl = [[WDScrollableSegmentedControl alloc] initWithFrame:frame];
// space between buttons
segmentedControl.padding = 10.;
// space before first button and after last button
segmentedControl.edgeMargin = 0.;
// indicator height
segmentedControl.indicatorHeight = 3.;
// indicator animation duration
segmentedControl.indicatorMoveDuration = 0.25;
// font
segmentedControl.font = [UIFont systemFontOfSize:16.];
// colors
segmentedControl.indicatorColor = [UIColor blackColor];
segmentedControl.buttonColor = [UIColor blackColor];
segmentedControl.buttonHighlightColor = [UIColor grayColor];
segmentedControl.buttonSelectedColor = [UIColor blueColor];
// use this method if you want to change colors dynamically
[segmentedControl setButtonColor:[UIColor greenColor] forState:UIControlStateNormal];
最后设置数据和代理
scrollSegment.buttons = @[@"Foo", @"Button 1", @"Button 2", @"Another Button", @"Bar", @"Button Again", @"Finally"];
scrollSegment.delegate = self;
// this is what your delegate should implement
- (void)didSelectButtonAtIndex:(NSInteger)index;
如果您在使用导航控制器,别忘了设置
self.automaticallyAdjustsScrollViewInsets = NO;
否则会干扰分段控件的内容大小
要运行示例项目,先从仓库中克隆该副本,然后在Example目录中运行pod install
。
iOS 8.0或更高版本。
WDScrollableSegmentedControl可通过CocoaPods获得。要安装它,只需将以下行添加到Podfile中
pod "WDScrollableSegmentedControl"
Wildog, [email protected]
WDScrollableSegmentedControl可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。