FGLSortSegmentedControl is a UISegmentedControl subclass that appends an ascending or descending string to the selected segment's title.
self.segmentedControl = [[FGLSortSegmentedControl alloc] initWithItems:@[@"Name",@"Date",@"Size"]];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
self.navigationItem.titleView = self.segmentedControl;
The segmented control can be placed in any view.
- As the titleView property of a UINavigationController
- As a UIBarButtonItem in a UIToolbar
- As subview of another view
[self.segmentedControl addTarget:self action:@selector(updateSortingInformation:) forControlEvents:UIControlEventValueChanged];
- (void)updateSortingInformation:(id)sender
{
NSLog(@"Index %d (%@)", [sender selectedSegmentIndex], [sender isAscending] ? @"Ascending" : @"Descending");
}
Read the full documentation
- iOS 5.1.1
- Apple LLVM 4.0+ (ARC, auto-synthesize, literals and subscripting)
Feel free to fork and submit pull requests. This project is very early in development and I'm open to any improvements.
FGLSortSegmentedControl is available under the MIT license. See the LICENSE file for more info.