How to create the appearance of keyboard accessories using the automatic layout in the interface builder?

I want to add a Finish button and a segmented control to the Decimal Pad keyboard. Ideally, I would like to lay out the presentation of keyboard accessories using Auto Layout in Interface Builder.

Is it possible? Am I creating a new XIB or can I do this in an existing storyboard script? How to attach an accessory view to the corresponding text box?

+4
source share
1 answer

Could you do this programmatically?

UIToolbar UITextField , UISegmentedControl;

UIToolbar *keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithFrame:...
// Customize segmentedControl properties here.

UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(doneButtonPressed)];

[keyboardToolbar setItems:[NSArray arrayWithObjects:flexibleSpace, doneButton, nil]];
[keyboardToolbar addSubview:segmentedControl];
[textField setInputAccessoryView:keyboardToolbar];

EDIT: IB, , , , setInputAccessoryView viewDidLoad.

+12

Source: https://habr.com/ru/post/1568386/


All Articles