When I add a UIToolBar, it appears to be 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 anything wrong?
Having come across this issue myself I found that the toolbar must either be instantiated with a non-zero frame, or have sizeToFit
called on it.
e.g.
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
try this code for UIToolBar Transparent :
self.toolbar.setBackgroundImage(UIImage(),
forToolbarPosition: UIBarPosition.Any,
barMetrics: UIBarMetrics.Default)
self.toolbar.setShadowImage(UIImage(),
forToolbarPosition: UIBarPosition.Any)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With