使用UIToolBar给textFiled的inputView添加按钮

来源:互联网 发布:阿里郎软件 编辑:程序博客网 时间:2024/05/24 23:12
  • 首先,textField的inputView属性可以指定其他视图代替keyBoard弹出。

    // 创建工具条UIToolbar *toolBar = [[UIToolbar alloc] init];// 设置工具条的颜色  toolBar.barTintColor = [UIColor cyanColor];// 设置工具条的frametoolBar.frame = CGRectMake(0, 0, self.view.frame.size.width, 44);// 给工具栏添加按钮UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction)];UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction)];UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction)];toolBar.items = @[item1, item2, flexibleItem, item3];self.textFiled.inputAccessoryView = toolBar;
原创粉丝点击