iOS自定义键盘

作者: Fatm | 来源:发表于2016-04-19 23:13 被阅读1745次

    对于有输入功能的控件,例如UITextField,可以给控件的inputView属性赋值,实现自定义键盘的功能

    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 300)];
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    [button setTitle:@"1" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor whiteColor];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [view addSubview:button];
    
    [button addTarget:self action:@selector(touchAction) forControlEvents:UIControlEventTouchUpInside];
    
    _textField.inputView = view;
    

    点击下载DEMO

    也可以给控件的inputAccessoryView赋值UIToolbar的对象设置工具条。

    如果结合第三方键盘监听事件的库IQKeyboard的话,效果更好。

    相关文章

      网友评论

      本文标题:iOS自定义键盘

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