Fix: UISegmentedControl Selected Segment Color Not Changing in iOS 13

Fix: UISegmentedControl Selected Segment Color Not Changing in iOS 13

Written by

in

Quick answer: In iOS 13, use selectedSegmentTintColor to set the selected segment’s background color and backgroundColor for the control’s overall background. Set title colors with setTitleTextAttributes for .normal and .selected states. Wrap the code in an #available(iOS 13.0, *) check for backward compatibility.

Why this happens

iOS 13 introduced a redesigned UISegmentedControl with a new visual style. The legacy tintColor property no longer controls the selected segment’s background, the divider lines, or the border. Instead, Apple split the appearance responsibilities across several properties. Existing code that relied on tintColor for the selected segment highlight stops working, leaving the selected segment with the system default color.

The control now exposes a dedicated selectedSegmentTintColor property (added in iOS 13 beta 3) specifically for the selected segment’s background. The overall control background uses backgroundColor, while title colors are still managed through setTitleTextAttributes(_:for:) with .normal and .selected states. If you use template images, tintColor still colors those images, but you may need three distinct colors (background, selected segment, and tint) for full visibility.

How to fix it

1. Use the modern iOS 13+ API (recommended)

Set backgroundColor for the control’s chrome, selectedSegmentTintColor for the active segment, and configure title attributes for both states. Guard the code with an availability check so it compiles and runs on earlier iOS versions.

import UIKit

func configureSegmentedControl(_ control: UISegmentedControl) {
    if #available(iOS 13.0, *) {
        // Overall control background
        control.backgroundColor = .systemBackground

        // Selected segment background
        control.selectedSegmentTintColor = .systemBlue

        // Optional border
        control.layer.borderColor = UIColor.systemBlue.cgColor
        control.layer.borderWidth = 1
        control.layer.cornerRadius = 8
        control.layer.masksToBounds = true

        // Unselected segment titles
        let normalAttributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: UIColor.label,
            .font: UIFont.preferredFont(forTextStyle: .subheadline)
        ]
        control.setTitleTextAttributes(normalAttributes, for: .normal)

        // Selected segment titles
        let selectedAttributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: UIColor.white,
            .font: UIFont.preferredFont(forTextStyle: .subheadline)
        ]
        control.setTitleTextAttributes(selectedAttributes, for: .selected)
    } else {
        // iOS 12 and earlier fallback
        control.tintColor = .systemBlue
        let attributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: UIColor.label
        ]
        control.setTitleTextAttributes(attributes, for: .normal)
        control.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)
    }
}

Call this method in viewDidLoad or after creating the segmented control programmatically. If you’re using a storyboard or xib, create an @IBOutlet and configure it in viewDidLoad.

2. Apply appearance globally with UIAppearance (optional)

To style every UISegmentedControl in the app without per-instance code, use the appearance proxy in AppDelegate or SceneDelegate.

if #available(iOS 13.0, *) {
    let appearance = UISegmentedControl.appearance()
    appearance.backgroundColor = .systemBackground
    appearance.selectedSegmentTintColor = .systemBlue

    let normalAttrs: [NSAttributedString.Key: Any] = [
        .foregroundColor: UIColor.label
    ]
    let selectedAttrs: [NSAttributedString.Key: Any] = [
        .foregroundColor: UIColor.white
    ]
    appearance.setTitleTextAttributes(normalAttrs, for: .normal)
    appearance.setTitleTextAttributes(selectedAttrs, for: .selected)
}

Note that per-instance settings override the appearance proxy. Use this approach when your design system calls for consistent segment controls across the app.

3. Handle template images correctly

If your segments use template images (rendering mode .alwaysTemplate), the control’s tintColor colors those images. Because the selected segment uses selectedSegmentTintColor as its background, the image becomes invisible if tintColor matches either the background or the selected tint. Choose a third, contrasting color for tintColor, or switch to non‑template images and leave tintColor alone.

if #available(iOS 13.0, *) {
    control.backgroundColor = .systemGray6
    control.selectedSegmentTintColor = .systemBlue
    control.tintColor = .systemOrange // distinct from the other two
}

How to prevent it

  • Adopt the iOS 13+ properties (selectedSegmentTintColor, backgroundColor) as soon as your deployment target allows.
  • Keep the #available(iOS 13.0, *) guard until you drop iOS 12 support.
  • Define a small styling helper or appearance proxy configuration so every segmented control stays consistent.
  • Test both light and dark modes; use semantic colors (UIColor.label, UIColor.systemBackground) instead of hard‑coded values.
  • Verify template image visibility against all three color roles (background, selected tint, tint).

FAQ

Does selectedSegmentTintColor work on iOS 12 if I set it via @available?

No. The property does not exist in the iOS 12 SDK. The #available guard prevents the compiler from emitting a call to a missing selector, but the property simply has no effect on iOS 12. Use the tintColor fallback inside the else branch for older versions.

Why does my segmented control still show the system blue selection after setting selectedSegmentTintColor?

Ensure you are setting the property after the control is initialized and before it appears on screen. If you use a storyboard, the control may be created with the system appearance; call your configuration in viewDidLoad or viewWillAppear. Also confirm you are not overriding the color later in layoutSubviews or via an appearance proxy with a lower precedence.

Can I animate the selected segment color change?

selectedSegmentTintColor is not animatable through standard UIView.animate blocks. The color snaps immediately when the selection changes. If you need a cross‑fade, you would have to subclass UISegmentedControl and manage a custom background layer yourself, which is rarely worth the effort.

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.