How do I create a keyboard accessory view with Auto Layout in Interface Builder?(如何在 Interface Builder 中使用自动布局创建键盘附件视图?)
问题描述
我想将完成"按钮和分段控件添加到小数点键盘.理想情况下,我想在 Interface Builder 中使用 Auto Layout 布局键盘附件视图.
I want to add a "Done" button and a segmented control to a Decimal Pad keyboard. Ideally I would like to lay out a keyboard accessory view with Auto Layout in Interface Builder.
这甚至可能吗?我是创建一个新的 XIB 还是可以在现有的 Storyboard 场景中以某种方式进行?如何将附件视图附加到相应的文本字段?
Is this even possible? Do I create a new XIB or can I do it in the existing Storyboard scene somehow? How do I attach the accessory view to the appropriate text field?
推荐答案
您介意以编程方式进行吗?
Would you mind doing it programmatically?
通常,您将 UIToolbar 与您的项目一起带到 UITextField,但您可能需要对 UISegmentedControl 进行子视图;
Typically you take a UIToolbar to a UITextField with your items, but you may need to subview the 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 中创建工具栏,但您必须将其拖出视图并拖到包含场景的左侧边栏并将其链接到参考插座,然后使用 setInputAccessoryView 分配它
在你的 viewDidLoad
中.
It is possible to create the toolbar initially in IB, but you have to drag it off the view and to the left hand sidebar containing the scene and link it to a reference outlet, then assign it with setInputAccessoryView
in your viewDidLoad
.
这篇关于如何在 Interface Builder 中使用自动布局创建键盘附件视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Interface Builder 中使用自动布局创建键盘附件视图?
基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01