Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a UITextview as a toolbar item

I am creating a messaging app for iPhone. I want the user to have the capability of entering a newline while pressing return. But I am having trouble putting a UITextview inside the toolbar item. I have seen the same with UITextView. When return key is pressed i want to get the new line in UITextField.Is this possible.enter image description here

Please help Thanks in advance.

like image 814
Senorina Avatar asked Jun 27 '11 05:06

Senorina


1 Answers

You can't add it using IB but you can do it programmatically. You will need to set its contentInset so that the text content is not pushed up on editing because the content will become invisible due to the text view's constrained size. I have added that in the example code below.

Example Code

UITextView * textView = [[[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 32)] autorelease];
textView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
UIBarButtonItem * barItem = [[[UIBarButtonItem alloc] initWithCustomView:textView] autorelease];

self.toolbar.items = [NSArray arrayWithObject:barItem];
like image 160
Deepak Danduprolu Avatar answered Sep 23 '22 06:09

Deepak Danduprolu