UIToolBar is transparent

When I add a UIToolBar, it looks transparent. However, I do not want this to happen. Here is my code:

var done = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: Selector("done")) if let font = UIFont(name: "Avenir", size: 17.0) { done.setTitleTextAttributes([NSFontAttributeName: font], forState: .Normal) } toolBar.items = [done] toolBar.barStyle = UIBarStyle.Default self.birthdayTextField.inputAccessoryView = toolBar 

Am I doing something wrong?

+6
source share
4 answers

Having received this problem, I found that the toolbar should either be created with a non-zero frame, or called sizeToFit .

eg.

  let tb = UIToolbar() tb.translucent = false tb.items = [UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil), UIBarButtonItem.init(title: "A button", style: .Plain, target: self, action: Selector("someAction:"))] tb.sizeToFit() userField?.inputAccessoryView = tb 

or

  let tb = UIToolbar(CGRectMake(0,0,view.frame.width,44)) tb.translucent = false tb.items = [UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil), UIBarButtonItem.init(title: "A button", style: .Plain, target: self, action: Selector("someAction:"))] userField?.inputAccessoryView = tb 
+3
source

try this code for UIToolBar Transparent:

 self.toolbar.setBackgroundImage(UIImage(), forToolbarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default) self.toolbar.setShadowImage(UIImage(), forToolbarPosition: UIBarPosition.Any) 
+1
source

This should disable the effect of transparency / transparency.

 toolbar.translucent = false 
0
source

try it

 toolBar.barStyle = UIBarStyle.Black 

and make sure toolBar.translucent = false

0
source

All Articles