Arefly Arefly - 1 month ago 5
Swift Question

inputAccessoryView's UIToolbar turns black when rotating in iOS

So here is my code:

override func viewDidLoad() {
// Do any additional setup after loading the view, typically from a nib.

let keyBoardToolBar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 44))
keyBoardToolBar.barStyle = .Default

let flexSpaceKeyboardBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)

let doneKeyboardBarButtonItem = UIBarButtonItem(title: "Done", style: .Done, target: self, action: nil)

let wordKeyboardBarButtonItem = UIBarButtonItem(title: "Button 1", style: .Plain, target: self, action: nil)

var barItems: [UIBarButtonItem] = []

keyBoardToolBar.setItems(barItems, animated: true)

self.myTV.inputAccessoryView = keyBoardToolBar

And when I am turning the device, the UIToolBar become black:


So is there anyway to fix it? Thanks!

BTW: In Simulator I cannot see UIToolBar turning black.


Fixed by adding: (not sure what cause it though)

keyBoardToolBar.translucent = false
keyBoardToolBar.barTintColor = UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1)

UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1) is the default background color of the UIToolBar from here