6

这是我的代码:

override func viewDidLoad() {
    super.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] = []
    barItems.append(wordKeyboardBarButtonItem)
    barItems.append(flexSpaceKeyboardBarButtonItem)
    barItems.append(doneKeyboardBarButtonItem)

    keyBoardToolBar.setItems(barItems, animated: true)

    self.myTV.inputAccessoryView = keyBoardToolBar
}

当我转动设备时,UIToolBar 变黑:(点击再次查看此 GIF)

黑色的

那么有没有办法解决呢?谢谢!

顺便说一句:在模拟器中,我看不到 UIToolBar 变黑。

4

1 回答 1

6

通过添加修复:(但仍不清楚导致它的原因)

keyBoardToolBar.isTranslucent = 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)这里的 UIToolBar 的默认背景颜色)

于 2015-12-15T13:20:37.387 回答