Почему мой UIToolbar появляется в странной позиции? - PullRequest
0 голосов
/ 22 января 2012

Я хочу добавить UIToolbar к клавиатуре для моего UITextField. Вот код, который я использую:

    UIToolbar *toolbar = [[UIToolbar alloc] init];
    toolbar.tintColor = [UIColor blackColor];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                                                                   style:UIBarButtonItemStyleBordered 
                                                                  target:self 
                                                                  action:@selector(someFunction)];
    doneButton.tintColor = [UIColor blackColor];
    UISegmentedControl *directionControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Back", @"Next", nil]];
    directionControl.tintColor = [UIColor blackColor];
    directionControl.segmentedControlStyle = UISegmentedControlStyleBar;
    [directionControl addTarget:self action:@selector(directionControlPressed) forControlEvents:UIControlEventValueChanged];
    UIBarButtonItem *segItem = [[UIBarButtonItem alloc] initWithCustomView:directionControl];
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
    [toolbar setItems:[NSArray arrayWithObjects:segItem, flexibleSpace, doneButton, nil]];

    // Assign the toolbar to the text fields
    self.textField.inputAccessoryView = toolbar;

Однако, вот как это выглядит, когда я запускаю код:

enter image description here

toolbar не кажется достаточно высоким; Также я заметил, что оттенок цвета панели инструментов не был подтвержден.

Пожалуйста, кто-нибудь может мне помочь?

1 Ответ

1 голос
/ 22 января 2012

Думаю, вам нужно установить рамку панели инструментов, хотя бы ее размер. Насколько я помню, я использовал [toolbar sizeToFit], чтобы получить высоту, и пришлось использовать ширину окна, чтобы получить ширину.

...