简体   繁体   中英

Text disappearing when I add gradient background to UIPicker in Swift 3

I am trying to add a gradient background to my picker in the same way that I have added a gradient background to my VC.

When I do this via the code below, the gradient is added but the text disappears from view. Although the picker still behaves as if the text is there.

My guess is it's something to do with the .insertSublayer placing the gradient background over the top off the text.

override func viewDidLoad() {

    let background = CAGradientLayer().bespokeColor()
    background.frame = self.view.bounds
    self.view.layer.insertSublayer(background, at: 0)

    let pickerBackground = CAGradientLayer().bespokeColor()
    pickerBackground.frame = self.Picker.bounds
    self.Picker.layer.insertSublayer(pickerBackground, at: 0)

}

How do I get around this?

Try adding the gradientLayer to the picker subview at index: 2

objective-c code is given below.

   [[[self._picker1  subviews] objectAtIndex:2] insertSublayer:pickerBackground atIndex:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM