1

I'm in the process of learning iOS development and have two simple and related questions: 1. How can I add several rows of items to one UIToolBar and is it possible at all? I want one UISearchBar and two rows of UIBarButtonItems (based on UIButton) on one UIToolbar. How can I implement this? 2. Is it possible to handle such kind of event: clicking on definite place on UIButton`UIBarButtonItem`? Now I'm just using:

 const CGPoint touchLocation = [touch locationInView:button];
Oleksandr Karaberov
  • 12,223
  • 10
  • 39
  • 68

1 Answers1

2

1.A. You might try setting up a view with all the buttons as you want and applying it to the toolbar via its initWithCustomView: (I think those might have to be regular buttons, not barButtonItems, which can't be framed so flexibly -- in which case it's not going to behave quite like a toolbar.) But will it all fit? If not, you might try increasing the height of the toolbar, but there are complications: reframe toolbar

1.B. Alternatively, you could forget the toolbar and make your own subview at the bottom of the screen, with whatever frame you choose and as many buttons as you want. This would be much easier and would probably raise fewer eyebrows at Apple.

2.A. Look into UIGestureRecognizer and its subclass UITapGestureRecognizer. You can use it to turn any view or rect of a view into a button. When its delegate method is called, you can do anything you want to the images/views involved.

2.B. Alternatively, you could make an image for the depressed/highlighted state of a custom UIButton (buttonWithType:UIButtonTypeCustom) that displays only the "cross" image. That would probably be the simpler choice.

Community
  • 1
  • 1
Wienke
  • 3,703
  • 25
  • 38