In my iOS application i have a UITextView
in the center of a UIToolbar
, an UIImage
on the left of the UITextView
and a Button on the right of the UITextView
. This is my code:
UIBarButtonItem *sendButton = [[UIBarButtonItem alloc] initWithTitle:@"Send" style:UIBarButtonItemStylePlain target:self action:@selector(dismissKeyboard)];
UIImage *image = [UIImage imageNamed:@"smile.png"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *smile = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(dismissKeyboard)];
UIBarButtonItem *textview = [[UIBarButtonItem alloc] initWithCustomView:_newMessageTextView];
newMessageToolbar.items = [NSArray arrayWithObjects: smile, textview, sendButton, nil];
This is the result:
My problem is when i'm going to write multiline text. While the button is fixed to the UIToolbar
's bottom, the UIImage
moves in the center vertically:
I don't understand why this happens, i'd like to have the UIImage
fixed to the bottom too. How can i solve this?
In your _newMessageTextView's text change delegate method, when input text modify height of textView, add following code to adjust UIBarButtonItem smile's imageInsets:
UIBarButtonItem *smile = [newMessageToolbar.items objectAtIndex:0];
[smile setImageInsets:UIEdgeInsetsMake(0, 0, (/* Calculate bottom inset value*/)*-1, 0)];