iOS 输入附件视图(工具栏)
示例
在键盘上方添加附件视图。这通常用于添加下一个/上一个按钮,或其他按钮,例如“完成/提交”(尤其是对于没有内置返回键的数字/电话/小数键盘类型)。
迅速
let textField = UITextField() //但是初始化
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 0)
let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem: .Done, target: self, action: Selector("done"))
let items = [flexibleSpace, doneButton] //将完成按钮推到右侧
toolbar.setItems(items, animated: false) //ortoolbar.items=...
toolbar.sizeToFit()
textField.inputAccessoryView = toolbar目标C
UITextField *textField = [[UITextField alloc] init];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];
NSArray *items = @[
flexibleSpace,
doneButton
];
[toolbar setItems:items];
[toolbar sizeToFit];
textField.inputAccessoryView = toolbar;
热门推荐
2 带猫的祝福语简短
10 同学贺卡励志祝福语简短
11 新年祝福语创意简短霸气
12 员工喜事祝福语简短精辟
13 奶奶的生日简短祝福语
14 可爱小狗祝福语简短
15 感恩老师祝福语简短独特
16 幼儿转园祝福语简短
17 酒仙网红包祝福语简短
18 放射医生祝福语简短精辟