![](/img/trans.png)
[英]How to add views in an existing view made in Interface Builder with Auto Layout?
[英]How do I create a keyboard accessory view with Auto Layout in Interface Builder?
我想在Decimal Pad鍵盤上添加一個“Done”按鈕和一個分段控件。 理想情況下,我想在Interface Builder中使用自動布局布置鍵盤附件視圖。
這甚至可能嗎? 我是否創建了一個新的XIB,或者我可以在現有的Storyboard場景中以某種方式創建它? 如何將附件視圖附加到相應的文本字段?
你介意以編程方式做嗎?
通常,您將UIToolbar帶到包含項目的UITextField,但您可能需要子視圖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中創建工具欄,但您必須將其拖離視圖和包含場景的左側邊欄並將其鏈接到參考插座,然后在viewDidLoad
使用setInputAccessoryView
進行分配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.