iOS
UISegmentedControl
iOS 13
UI customization
Swift programming

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

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

On iOS 13, the recommended way to customize UISegmentedControl colors changed compared with many older workarounds. The most important properties are selectedSegmentTintColor for the selected segment and title text attributes for selected and normal states.

Set the Selected Segment Color

The selected segment background tint is controlled with selectedSegmentTintColor.

swift
let segmented = UISegmentedControl(items: ["One", "Two", "Three"])
segmented.selectedSegmentIndex = 0
segmented.selectedSegmentTintColor = .systemBlue

This is the main iOS 13-era property for the selected segment appearance.

Set Title Colors for Normal and Selected States

Text color is controlled through title text attributes.

swift
1segmented.setTitleTextAttributes([
2    .foregroundColor: UIColor.darkGray
3], for: .normal)
4
5segmented.setTitleTextAttributes([
6    .foregroundColor: UIColor.white
7], for: .selected)

Together with selectedSegmentTintColor, this gives you the usual selected and unselected visual states.

Understand What You Cannot Style Directly

Not every part of the control is equally customizable through one simple property. In iOS 13, Apple’s updated segmented-control appearance reduced the usefulness of some older image-based or tint-based tricks from previous versions.

That is why older answers that rely only on tintColor often do not behave the way you expect on iOS 13.

Test in Light and Dark Appearance

Because iOS 13 introduced system-wide dark mode, color customization should be verified in both appearances.

If you hard-code colors, make sure they still provide contrast in different interface styles. Dynamic system colors are often safer when the control must adapt automatically.

Common Pitfalls

  • Using pre-iOS-13 tintColor advice and expecting it to control the segmented control the same way.
  • Setting the selected segment tint but forgetting to update title text attributes for contrast.
  • Hard-coding colors that become unreadable in dark mode.
  • Expecting every visual detail of UISegmentedControl to be customizable through one property.
  • Testing only one selected state and ignoring how unselected segments look.

Summary

  • On iOS 13, use selectedSegmentTintColor for the selected segment background.
  • Use setTitleTextAttributes to control text colors for normal and selected states.
  • Do not rely on older tintColor-only customization advice.
  • Check contrast in both light and dark appearances.
  • Combine background and text customization to get a readable segmented control.

Course illustration
Course illustration

All Rights Reserved.