Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - UIToolBar as inputAccessoryView for UITextView

I've added a UIToolBar with a UIBarButtonItem as inputAccessoryView for a UITextView. It works fine but the UIBarButtonItem is touchable outside it's frame, perhaps 50 pixels outside to the right. It's no big deal but it annoys me. Anyone know why?

This is my code (ARC):

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)];
toolBar.barStyle = UIBarStyleBlack;
toolBar.translucent = YES;

UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneWriting:)];
[toolBar setItems:[NSArray arrayWithObjects:doneButton, nil]];

self.messageTextView.inputAccessoryView = toolBar;
like image 733
Peter Warbo Avatar asked Feb 07 '12 09:02

Peter Warbo


1 Answers

In iOS 6 it seems to behave as expected. Nice tip: If you want the button to appear on the right instead of the left, use one of these:

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

Then initialise the toolbar with:

[toolBar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
like image 184
radsdau Avatar answered Sep 28 '22 20:09

radsdau