The styled swipeable segmented control used in Next
Either manually add the NXTSegmentedControl.h/m files to your project, or add the NXTSegmentedControl cocoapod by adding the following line to your podfile:
pod 'NXTSegmentedControl'
Start by importing the header.
#import <NXTSegmentedControl/NXTSegmentedControl.h>
Create the segmented control, and customize the appearance.
NXTSegmentedControl *segmentedControl = [[NXTSegmentedControl alloc] initWithItems:@[@"Post", @"Comments"]];
segmentedControl.tintColor = [UIColor redColor];
[segmentedControl addTarget:self action:@selector(segmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview: segmentedControl];
Finally implement your action method.
- (void)segmentedControlValueChanged:(id)sender {
NXTSegmentedControl *segmentedControl = (NXTSegmentedControl *)sender;
NSString *t = [NSString stringWithFormat:@"%d", segmentedControl.selectedSegmentIndex];
NSLog(t);
}
NXTSegmentedControl uses the target action pattern just like most controls from UIKit. This creation code should be nearly identical to UISegmentedControl creation.