美文网首页
使用UIToolBar给textFiled的inputView添

使用UIToolBar给textFiled的inputView添

作者: hgq | 来源:发表于2016-06-17 18:15 被阅读253次
  • 首先,textField的inputView属性可以指定其他视图代替keyBoard弹出。

    // 创建工具条
    UIToolbar *toolBar = [[UIToolbar alloc] init];
    // 设置工具条的颜色
      toolBar.barTintColor = [UIColor cyanColor];
    // 设置工具条的frame
    toolBar.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;

相关文章

网友评论

      本文标题:使用UIToolBar给textFiled的inputView添

      本文链接:https://www.haomeiwen.com/subject/mauvdttx.html