Imitate after iOS7 style segmented controls! It is simple, Elegant, practical!
iOS8.0 and later
- download the newest code , and
#import "RFSegmentView.h"
- use blow method to initialize
- (instancetype)initWithFrame:(CGRect)frame titles:(NSArray<NSString *> *)titles;
- set TintColor and delegate or block handler if needed
- implement delegate callBack function if you use delegate
- (void)segmentView:(RFSegmentView * __nullable)segmentView didSelectedIndex:(NSUInteger)selectedIndex;
or use block callback
segmentView.handlder = ^ (RFSegmentView * __nullable view, NSUInteger selectedIndex) {
// doSomething
};
first add to config to Podfile
pod 'RFSegmentView', '~>1.3.0'
then import header file and enjoy it.
#import <RFSegmentView.h>
RFSegmentView* segmentView = [[RFSegmentView alloc] initWithFrame:aRect titles:@[@"spring",@"summer",@"autumn",@"winnter"]];
segmentView.tintColor = aColor;
//segmentView.delegate = self;
segmentView.handlder = ^ (RFSegmentView * __nullable view, NSUInteger selectedIndex) {
// doSomething
};
[self.view addSubview:segmentView];
Ps:you can also use delegate callback.
You can download binary release from the latest releases.
RFSegmentView is released under the MIT license. See LICENSE for details.