Question

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:

enter image description here

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:

enter image description here

I don't understand why this happens, i'd like to have the UIImage fixed to the bottom too. How can i solve this?

Was it helpful?

Solution

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)];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top