Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么我的UIToolbar出现在一个奇怪的位置?_Iphone_Ios_Uitoolbar_Uikeyboard - Fatal编程技术网

Iphone 为什么我的UIToolbar出现在一个奇怪的位置?

Iphone 为什么我的UIToolbar出现在一个奇怪的位置?,iphone,ios,uitoolbar,uikeyboard,Iphone,Ios,Uitoolbar,Uikeyboard,我想为我的UITextField在键盘上添加一个UIToolbar。以下是我正在使用的代码: UIToolbar *toolbar = [[UIToolbar alloc] init]; toolbar.tintColor = [UIColor blackColor]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"

我想为我的
UITextField
在键盘上添加一个
UIToolbar
。以下是我正在使用的代码:

    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;
但是,以下是我运行代码时的情况:

工具栏
似乎不够高;我还注意到工具栏的色调尚未确认


有人能帮我吗?

我想你需要设置工具栏的框架,至少它的大小。我记得,我使用了
[toolbar sizeToFit]
来获得高度,并且必须使用窗口宽度来获得宽度。

这非常有效!它解决了高度、宽度和色调的问题。非常感谢你!由于工具栏的大小为
CGSizeZero
,因此没有显示色调。