Search code examples
iosswiftuser-interfaceuipickerview

How do I get the grey color/translucency I see on UIPickerDate default view on my own custom Picker?


I have created a UI Picker but the default is just it being transparent. I would like to use/be given the RGB + translucency values that makes the grey color that is commonly used on picker views.

It is the same grey like the defualt color for a programmatic UI Date Picker. Thank you! I need this to be in alignment with Apple's Human Interface Guidelines.

Added a picture of the background color/translucency I need below:

enter image description here


Solution

  • iPhone SDK has two types of gray color both have opacity 1.

    iOS 13 also introduces a range of six opaque gray colors you can use in rare cases where translucency doesn't work well.

    https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/

    And for changing the background color.

    light gray color:

    picker.backgroundColor = UIColor.lightGray
    

    dark gray color:

    picker.backgroundColor = UIColor.darkGray
    

    if you want some transparency on the picker view. You can add Gradient on it.

            let view = UIView(frame: CGRect(x: 0, y: 0, width: picker.frame.width, height: picker.frame.height))
            let gradient = CAGradientLayer()
    
            gradient.frame = view.bounds
            gradient.colors = [UIColor.white.cgColor, UIColor.lightGray.cgColor]
    
            picker.layer.insertSublayer(gradient, at: 0)
    

    find the image as it looks with gradient and light gray color. picker view with gradient