gpt4 book ai didi

iphone - 为什么我的 UIToolbar 出现在奇怪的位置?

转载 作者:行者123 更新时间:2023-11-29 04:50:20 24 4
gpt4 key购买 nike

我想为我的 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;

但是,这是我运行代码时的样子:

enter image description here

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

请问有人可以帮我吗?

最佳答案

认为您需要设置工具栏的框架,至少是其大小。我记得,我使用 [toolbar sizeToFit] 来获取高度,并且必须使用窗口宽度来获取宽度。

关于iphone - 为什么我的 UIToolbar 出现在奇怪的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com