I still stuck in fixing my code for iOS 7.1 with the new option "button shapes". Selecting it is increasing the width of an UIButtonItem
in my programmatically created toolbar. This will move an text field to the right because I do not know how to get the (changing) available space in the toolbar to set the width for the textfield.
I tried to get the button size with customItem.customView.frame.size.width);
but it will always return "0.0".
I need to create the toolbar with button and textfield programmatically in order to provide the textfield. But until now I hard coded the textfield width (210) to fit it in the available space next to the button (too bad I know). I can't find a way to get the size of the button to fit the text field size nor do I find a solution to resize the textfield based on the "button shape" option.
What can I do? Thanks.
[self.navigationController setToolbarHidden:NO]; //animated:YES
[self.navigationController.toolbar setBarTintColor:[UIColor colorWithRed:0.8f green:0.0f blue:0.0f alpha:0.5]];
[self.navigationController.toolbar setTranslucent:YES];
// button
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithTitle:@"Simulation" style:UIBarButtonItemStylePlain target: self action: @selector(prepareResultView:)];
// text field
CGRect frame = CGRectMake(0, 0, 210, 30);
numberText= [[UITextField alloc] initWithFrame:frame];
numberText.autoresizingMask = UIViewAutoresizingFlexibleWidth;
numberText.borderStyle = UITextBorderStyleRoundedRect;
numberText.textColor = [UIColor blackColor];
numberText.font = [UIFont systemFontOfSize:18.0];
numberText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
numberText.textAlignment = NSTextAlignmentCenter;
numberText.placeholder = NSLocalizedString(@"Anzahl Berechnungen", @"Message");
numberText.backgroundColor = [UIColor whiteColor];
numberText.autocorrectionType = UITextAutocorrectionTypeNo;
numberText.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
numberText.returnKeyType = UIReturnKeyDone;
numberText.clearButtonMode = UITextFieldViewModeWhileEditing;
numberText.delegate = self;
[numberText setRightViewMode:UITextFieldViewModeAlways];
// textfield item
UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithCustomView:numberText];// behavior of number textfield see below
NSArray *items = [NSArray arrayWithObjects: customItem, customItem1, nil];
[self setToolbarItems:items animated:YES];