UIControlSegment background color is not transparent anymore on iOS13

uisegmentedcontrol ios 13
ios 13 segmented control corner radius

I have a UISegmentedControl. it was working fine before iOS13 (I set both backgroundColor and tintColor to clear). But now, I don't get the same result. My SegmentedControl has a light grey layer. I made some research but nothing work. (I have the same problem as this: https://forums.developer.apple.com/thread/123955)

Previous state:

current state - iOS13:

I also have face this issue to meet the design requirement. In my case SegmentedControl background color should be white color or clear color because view's background color was also white.

So I just add a white UImage in SegmentControl background and this trick worked for me.

if (@available(iOS 13.0, *)) {
   [segmentController setBackgroundImage:[UIImage imageNamed:@"someWhiteImage"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

Although it is not a perfect solution but my requirement meets using this trick. You may also add a solid color background image in background for now. Hopefully someone show us the right way of handling.

Required Design and before iOS 13

After iOS 13

So adding white background image worked for me

How to get transparent background …, How to get transparent background on UIControlSegment? Currently it only makes the `backgroundColor` set programatically darker. I want to set it to transparent or set a gradient image on it. But not totally yours. h ttps://medium. com/flawless-app-stories/ios-13-uisegmentedcontrol-3-important-changes- d3a94fdd6763. Hi, I would like to know how to get a transparent background in the new iOS 13's UIControlSegment. Currently it only makes the `backgroundColor` set programatically darker. I want to set it to transparent or set a gradient image on it. The current colors look terrible on my app and I am willing to move it to a third party solution.

.selectedSegmentTintColor defines the selected button color and .layer.backgroundColor the color for the whole UISegmentedControl background.

It turns out this won't work for background clear or white since on iOS 13 a sort of background image is added on the background and dividers of the segmented control.

A workaround is create an image from color with UIGraphicsGetImageFromCurrentImageContext. Try this:

class ViewController: UIViewController {

    @IBOutlet weak var segmentedControl: UISegmentedControl!

    override func viewDidLoad() {
        // Do any additional setup after loading the view.

        segmentedControl.setiOS12Layout(tintColor: .red)

extension UISegmentedControl {

    func setiOS12Layout(tintColor: UIColor) {

        if #available(iOS 13, *) {

            let background = UIImage(color: .clear, size: CGSize(width: 1, height: 32))
             let divider = UIImage(color: tintColor, size: CGSize(width: 1, height: 32))
             self.setBackgroundImage(background, for: .normal, barMetrics: .default)
             self.setBackgroundImage(divider, for: .selected, barMetrics: .default)
             self.setDividerImage(divider, forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)
             self.layer.borderWidth = 1
             self.layer.borderColor = tintColor.cgColor
             self.setTitleTextAttributes([.foregroundColor: tintColor], for: .normal)
             self.setTitleTextAttributes([.foregroundColor: UIColor.white], for: .selected)

        } else {

            self.tintColor = tintColor
extension UIImage {

    convenience init(color: UIColor, size: CGSize) {

        UIGraphicsBeginImageContextWithOptions(size, false, 1)
        let context = UIGraphicsGetCurrentContext()!
        context.fill(CGRect(origin: .zero, size: size))
        let image = UIGraphicsGetImageFromCurrentImageContext()!
        self.init(data: image.pngData()!)!


iOS 13 UISegmentedControl: 3 important changes, the 6% black background image (and the divider images) with a transparent image. Tint color does not work anymore While trying to pick a good background color for segmented controls in my app I Starting with iOS 13 a corner radius is set no matter if custom background images are used or not� In earlier versions of the .NET Framework, controls didn't support setting transparent backcolors without first setting the SetStyle method in the forms's constructor. In the current framework version, the backcolor for most controls can be set to Transparent in the Properties window at design time, or in code in the form's constructor.

You can create an extension to make your segmentcontrol clear


Here is the extention

extension UISegmentedControl {
    func clearBG() {
        setBackgroundImage(imageWithColor(color: UIColor.white), for: .normal, barMetrics: .default)
        setBackgroundImage(imageWithColor(color: UIColor.white), for: .normal, barMetrics: .default)
        setDividerImage(imageWithColor(color: .white), forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)

    // create a 1x1 image with this color
    private func imageWithColor(color: UIColor) -> UIImage {
        let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
        let context = UIGraphicsGetCurrentContext()
        let image = UIGraphicsGetImageFromCurrentImageContext();
        return image!

ios UIControlSegment背景颜色在iOS13上不再透明- 糯米PHP, 在iOS13之前,它运行良好(我将backgroundColor和tintColor都设置 UIControlSegment background color is not transparent anymore on iOS13. You should now see a pink colored background layer with an opacity of 50% that only applies to the background color and not the content. Here's a quick explanation of how the generated content (our background layer) is styled: To generate empty/invincible content we can simply set the content property's value to an empty string or a space

thanks @Maulik Pandya for the answer, I have improve your answer little bit.

extension UISegmentedControl {
  func clearBG() {
    let clearImage = UIImage().imageWithColor(color: .clear)
    setBackgroundImage(clearImage, for: .normal, barMetrics: .default)
    setBackgroundImage(clearImage, for: .selected, barMetrics: .default)
    setDividerImage(clearImage, forLeftSegmentState: .normal, rightSegmentState: .normal, barMetrics: .default)

public extension UIImage {
  public func imageWithColor(color: UIColor) -> UIImage {
    let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
    guard let context = UIGraphicsGetCurrentContext() else { return UIImage()}
    let image = UIGraphicsGetImageFromCurrentImageContext()
    return image!

Image background alters from transparent to white on iOS 13 [2020 , I uploaded PNG images with transparent backgrounds from Windows 10 to my Google Photos. My Google Photos app on iOS 12 shows the� It’s not necessary to use a website to change the background color. If you have a Windows 10 PC, you can use the preinstalled Paint 3D app to replace the background by white color.

Transparent UISearchBar in iOS 13 or newer, For changing the background in the UISearchBar you do not only need to set the .backgroundColor method, but also add some trick. UISearchBar� To use more than 2 colors (because why not), put the powerful rgba() to use and use 2 gradient parameters. Here’s an example with the background property holding an image and masking some portion of the image with a gradient of orange and transparent. Use a dominant color from the image or a completely contrast color for the rich look.

How to adjust the opacity of a view, Any SwiftUI view can be partially or wholly transparent using the Text("Now you see me") .padding() .background(Color.red) .opacity(0.3). Here’s how to change background color of dock and folders to any color. 1. Open this website and scroll down. Download the square images in color of your choice by tapping and holding on it. Remember that the image you download will be the color of your wallpaper although the dock will still be black.

Why is my PNG logo showing up with a white background? : FAQ, it will convert your transparent PNG file to a non-transparent JPG file. or download your PNG images from a weblink to get the transparent� The text nodes will take the background color or the parent views instead and will hide the image. Then we have to set backgroundColor: 'transparent' on the text nodes to fix it. This behavior also doesn't happen on Android, the <Text> nodes always have a transparent background by default. This causes a few surprises when developing something

  • Can you share the code where you're defining the colors on UIControlSegment?
  • Can you post the image of UI that you would like to achieve?
  • @MaulikPandya : I have update the post
  • @MarinaAguilar UIColor.clear