温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

iOS自定义键盘

发布时间:2020-08-19 05:24:43 来源:网络 阅读:757 作者:卓行天下 栏目:移动开发

对于有输入功能的控件,例如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的话,效果更好。



文/Fatm(简书作者)
原文链接:http://www.jianshu.com/p/dee8ef45a741
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI