UISegmentedControl-TitleWithImage
Apple's UISegmentedControl
is a great little object that's commonly used throughout the UI of our iOS apps. But do you know what really grinds my gears? UISegmentedControl
will let you set a title per segment, or an image per segment, but not both an image and a title. There needs to be a better way…
UISegmentedControl-TitleWithImage adds a couple of methods to UISegmentedControl
that let you do just that, namely, show both a title and an image within the same segment:
#import "ViewController.h"
#import <UISegmentedControl+TitleWithImage/UISegmentedControl+APSTitleWithImage.h>
@interface ViewController ()
@property (nonatomic, strong) IBOutlet UISegmentedControl *segmentedControl;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[@[@"Hello", @"World"] enumerateObjectsUsingBlock:^(NSString *t, NSUInteger i, BOOL *stop) {
[self.segmentedControl insertSegmentWithTitle:t
image:[UIImage bigUglyRedSquare]
atIndex:i
animated:NO];
}];
}
@end
Now, self.segmentedControl
will look like: