gpt4 book ai didi

ios - 如何在 Interface Builder 中使用自动布局创建键盘附件 View ?

转载 作者:可可西里 更新时间:2023-11-01 05:03:47 26 4
gpt4 key购买 nike

我想在 Decimal Pad 键盘上添加一个“完成”按钮和一个分段控件。理想情况下,我想在 Interface Builder 中使用自动布局布局键盘附件 View 。

这可能吗?我是创建一个新的 XIB 还是可以在现有的 Storyboard 场景中以某种方式创建?如何将附件 View 附加到适当的文本字段?

最佳答案

您介意以编程方式进行吗?

通常,您将 UIToolbar 与您的项目一起带到 UITextField,但您可能需要 subview UISegmentedControl;

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

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithFrame:...
// Customize segmentedControl's 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];

编辑:最初可以在 IB 中创建工具栏,但您必须将其拖出 View 并拖到包含场景的左侧边栏,并将其链接到引用 socket ,然后使用 setInputAccessoryView 分配它 在你的 viewDidLoad 中。

关于ios - 如何在 Interface Builder 中使用自动布局创建键盘附件 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27573045/

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