Minimal segmented control, scrollable, customizable, animatable, easy as hell to use.
Works perfectly with YTPageController:
Interface Builder is all you need:
... or you prefer code:
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];
Finally set the data and delegate:
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;
If you use it in a navigation controller, don't forget to set:
self.automaticallyAdjustsScrollViewInsets = NO;
Or it will mess with contentSize of the segmented control.
To run the example project, clone the repo, and run pod install
from the Example directory first.
iOS 8.0 or above.
WDScrollableSegmentedControl is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "WDScrollableSegmentedControl"
Wildog, i@wil.dog
WDScrollableSegmentedControl is available under the MIT license. See the LICENSE file for more info.