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
,因此没有显示色调。