How to add scrolling for UIBarButtonItem buttons on UIToolbar (to place many buttons on the toolbar)?
buttonDone = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonDoneDown)];
NSArray *itemsArray = [NSArray arrayWithObjects:buttonDone, nil];
[toolbar setItems:itemsArray];
Thanks a lot for the help!
For Swift
let's just say i want to add 7 UIBarButtonItem's to my UIToolBar
First Create a scrollView, then add toolBar as subview
// In viewDidLoad
let scrollView = UIScrollView(frame: CGRect(x: 0, y: view.frame.height-44, width: view.frame.width, height: 50))
let toolBar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 1000, height: scrollView.frame.height))
let btn1 = UIBarButtonItem()
let btn2 = UIBarButtonItem()
let btn3 = UIBarButtonItem()
let btn4 = UIBarButtonItem()
let btn5 = UIBarButtonItem()
let btn6 = UIBarButtonItem()
let btn7 = UIBarButtonItem()
toolBar.items = [btn1, btn2, btn3, btn4, btn5, btn6, btn7]
scrollView.addSubview(toolBar)
// The below line is important for scrollView to work
scrollView.contentSize = CGSize(width: 1000, height: 50)
Lastly add scrollView as your textField inputAccessoryView
textField.inputAccessoryView = scrollView
I hope it helps you :]
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