Switching ViewControllers with UISegmentedControl in iOS5

This code works pretty well for your purpose, I use it for one of my new apps. It uses the new UIViewController containment APIs that allow UIViewControllers inside your own UIViewControllers without the hassles of manually forwarding stuff like viewDidAppear: – (void)viewDidLoad { [super viewDidLoad]; // add viewController so you can switch them later. UIViewController … Read more

How to change the colors of a segment in a UISegmentedControl in iOS 13?

As of iOS 13b3, there is now a selectedSegmentTintColor on UISegmentedControl. To change the overall color of the segmented control use its backgroundColor. To change the color of the selected segment use selectedSegmentTintColor. To change the color/font of the unselected segment titles, use setTitleTextAttributes with a state of .normal/UIControlStateNormal. To change the color/font of the … Read more

Color Tint UIButton Image

As of iOS 7, there is a new method on UIImage to specify the rendering mode. Using the rendering mode UIImageRenderingModeAlwaysTemplate will allow the image color to be controlled by the button’s tint color. Objective-C UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; UIImage *image = [[UIImage imageNamed:@”image_name”] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; [button setImage:image forState:UIControlStateNormal]; button.tintColor = [UIColor redColor]; Swift let … Read more

Change font size of UISegmentedControl

I ran into the same issue. This code sets the font size for the entire segmented control. Something similar might work for setting the font type. Note that this is only available for iOS5+ Obj C: UIFont *font = [UIFont boldSystemFontOfSize:12.0f]; NSDictionary *attributes = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; [segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal]; EDIT: UITextAttributeFont has been deprecated … Read more

UISegmentedControl selected segment color

Here is the absolute simplest way to change the selected segment to any RGB color. No subclassing or hacks required. segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; UIColor *newTintColor = [UIColor colorWithRed: 251/255.0 green:175/255.0 blue:93/255.0 alpha:1.0]; segmentedControl.tintColor = newTintColor; UIColor *newSelectedTintColor = [UIColor colorWithRed: 0/255.0 green:175/255.0 blue:0/255.0 alpha:1.0]; [[[segmentedControl subviews] objectAtIndex:0] setTintColor:newSelectedTintColor]; This example shows the important steps: Sets … Read more