在我的iOS应用程序中,我UITextView
的中心位置UIToolbar
,UIImage
左侧的UITextView
和右侧的按钮UITextView
。这是我的代码:
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];
结果如下:
我的问题是我要写多行文字。当按钮固定在UIToolbar
的底部时,UIImage
会在中心垂直移动:
我不明白为什么会发生这种情况,我希望将UIImage
固定在底部。我该如何解决这个问题?
答案 0 :(得分:0)
在_newMessageTextView的文本更改委托方法中,当输入文本修改textView的高度时,添加以下代码来调整UIBarButtonItem smile的imageInsets:
UIBarButtonItem *smile = [newMessageToolbar.items objectAtIndex:0];
[smile setImageInsets:UIEdgeInsetsMake(0, 0, (/* Calculate bottom inset value*/)*-1, 0)];