I have a nice subclass of UIToolbar that I just wrote to do this, thanks to the code in the Oded post. It works great for a toolbar with 5 elements: button, flexible space, text box, flexible space, button. layoutSubviews , it can correctly adjust the width of the UITextField :
@implementation AdaptingTextFieldToolbar - (void)layoutSubviews { CGFloat totalItemsWidth = 0.0; CGFloat itemsMargin = 8.0; UIBarButtonItem *textFieldBarButtonItem; for (UIBarButtonItem *barButtonItem in self.items) {
David h
source share