Adding a UITextview as a Toolbar Item

I am creating a messaging application for iPhone. I want the user to be able to enter a new line when pressing return. But it's hard for me to put a UITextview inside a toolbar item. I saw the same with a UITextView. When the return key is pressed, I want to get a new line in a UITextField. Perhaps it. enter image description here

Please help Thanks in advance.

+6
source share
1 answer

You cannot add it using IB, but you can do it programmatically. You will need to set its contentInset so that the text content is not edited, because the content will become invisible due to the limited size of the text view. I added that in the example code below.

Code example

 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]; 
+6
source

Source: https://habr.com/ru/post/891421/


All Articles