neeraj
neeraj

Reputation: 1221

iOS UIToolbar recognizes touch

I made a vertical (in looks) toolbar programmatically. Using initWithFrame I set the width and height of the toolbar and sent it to extreme right.

Now I added a bar button item to the toolbar and set an action for it. But when I click anywhere on the toolbar, the action message is being sent. And I checked the sender, the sender is not the toolbar but the button.

I tried on another toolbar which I placed horizontally, the buttons are seen as tapped if I click in the vicinity of the button. And since now my toolber is vertical (but horizontal according to iOS), clicking anywhere on the toolbar calls the function.

I want to send the message only when I click on the button and not on the toolbar.

I want to use the camera icon provided by apple, so I am not in favor of using UIButton. (I can set a custom image, but it would be good if i can avoid that) I also think that placing a horizontal toolbar and using CGAffineTransform can solve the problem. But it would be nice if there is clean method.

Upvotes: 0

Views: 378

Answers (2)

Caleb
Caleb

Reputation: 124997

I don't believe that UIToolbar supports vertical orientation; you'll probably be better off rolling your own toolbar-like control.

Upvotes: 0

JoshRagem
JoshRagem

Reputation: 595

Using the transform is definitely the way to go.

Run the identity transform through this function and set it as the transform on your bar. I think it is a very simple solution.

It shouldn't be hard to set the transform right after you init with a normal frame. To avoid stretching you can make that frame using the values you are already using but swapping the x and y.

Upvotes: 1

Related Questions