自定义键盘类VolumeInputKeyboardView:

VolumeInputKeyboardView.h文件:

 #import <UIKit/UIKit.h>

 NS_ASSUME_NONNULL_BEGIN

 @interface VolumeInputKeyboardView : UIView
@property(weak, nonatomic) UITextField *m_textField;
@end NS_ASSUME_NONNULL_END

VolumeInputKeyboardView.m文件:

 switch  ::
#import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface VolumeInputKeyboardView : UIView
@property(weak, nonatomic) UITextField *m_textField;
@end NS_ASSUME_NONNULL_END switch ::
#import "VolumeInputKeyboardView.h"
#import "CommonFunc.h" @implementation VolumeInputKeyboardView - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self createTopBar];
float width = (CGRectGetWidth(self.frame) - ) / ;
for(int i = ; i < ; ++i)
{
[self createKey:[NSString stringWithFormat:@"%d",i] posX:(width * ((i - ) % ) + ((i - ) % )) posY:( + * ((i - )/)) width:width height:];
}
[self createKey:@"" posX: posY:( + * ) width:(width * + ) height:];
[self createKey:@"←" posX:(width * + ) posY:( + * ) width:(width) height:];
[self createKey:@"+" posX:(width + ) * posY: width:width height:];
[self createKey:@"-" posX:(width + ) * posY:( + * ) width:(width) height:];
}
return self;
} - (void)createTopBar
{
UIView *topView = [UIView new];
[topView setBackgroundColor:[UIColor darkGrayColor]];
[self addSubview:topView];
topView.frame = CGRectMake(, , CGRectGetWidth(self.frame), ); UILabel *lbInfo = [[UILabel alloc]initWithFrame:CGRectMake(, , CGRectGetWidth(topView.frame) / * - , CGRectGetHeight(topView.frame))];
[topView addSubview:lbInfo];
[lbInfo setText:@"一些提示信息"];
[lbInfo setLineBreakMode:NSLineBreakByWordWrapping];
[lbInfo setNumberOfLines:];
[lbInfo setFont:[UIFont systemFontOfSize:]];
[lbInfo setTextColor:[UIColor whiteColor]]; UIButton *btnFinish = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetWidth(topView.frame) / * , , CGRectGetWidth(topView.frame) / , CGRectGetHeight(topView.frame))];
[topView addSubview:btnFinish];
[btnFinish setTitle:@"完成" forState:UIControlStateNormal];
[btnFinish setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnFinish setBackgroundImage:[CommonFunc imageWithColor:[UIColor orangeColor]] forState:UIControlStateHighlighted];
[btnFinish addTarget:self action:@selector(hideKeyboard) forControlEvents:UIControlEventTouchUpInside];
} - (void)createKey:(NSString *)title posX:(float)posX posY:(float)posY width:(float)width height:(float)height
{
UIButton *btnKey = [[UIButton alloc]initWithFrame:CGRectMake(posX, posY, width, height)];
[self addSubview:btnKey];
[btnKey addTarget:self action:@selector(buttonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[btnKey setTitle:title forState:UIControlStateNormal];
[btnKey setBackgroundColor:[UIColor lightGrayColor]];
[btnKey setBackgroundImage:[CommonFunc imageWithColor:[UIColor orangeColor]] forState:UIControlStateHighlighted];
} - (void)buttonDidClicked:(UIButton*)sender
{
self.m_textField.text = sender.titleLabel.text;
} -(void)layoutSubviews{
[super layoutSubviews]; } - (void)hideKeyboard
{
//隐藏键盘
[self.m_textField endEditing:YES];
}
@end

调用的地方:

 VolumeInputKeyboardView *volumeKeyboard = [[VolumeInputKeyboardView alloc]initWithFrame:CGRectMake(, , SCREEN_WIDTH, )];

     volumeKeyboard.m_textField = self.m_textField;
//设置输入框的键盘为自定义的键盘
self.textField.inputView = volumeKeyboard;

最终实现的键盘效果如下:

iOS自定义键盘的简单实现的更多相关文章

  1. 【iOS自定义键盘及键盘切换】详解

    [iOS自定义键盘]详解 实现效果展示: 一.实现的协议方法代码 #import <UIKit/UIKit.h> //创建自定义键盘协议 @protocol XFG_KeyBoardDel ...

  2. ios 自定义键盘

    由于项目需要,需要自定义键盘.ios系统键盘会缓存键盘输入,并保存在系统目录下的文件里,并且是明文存储,存在帐号密码泄漏风险.在别人代码基础上修改了下,美化了下界面,去掉了字符输入,加了点击特效,截图 ...

  3. iOS 自定义键盘ToolBar(与键盘的弹出、收起保持一致)

    1.监听键盘改变的通知 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardWillCha ...

  4. ios之键盘的自定义

    一.键盘通知 当文本View(如UITextField,UITextView,UIWebView内的输入框)进入编辑模式成为first responder时,系统会自动显示键盘.成为firstresp ...

  5. iOS 自定义emoji表情键盘

    之前走了很多弯路,包括自己定以emoji表情,自己创建view类去处理图文混排 ,当把这些焦头烂额的东西处理完了才发现 ,其实系统自带键盘是如此的方便,iOS 系统自带的表情在view,textfie ...

  6. ios自定义数字键盘

    因为项目又一个提现的功能,textfiled文本框输入需要弹出数字键盘,首先想到的就是设置textfiled的keyboardType为numberPad,此时你会看到如下的效果:   但是很遗憾这样 ...

  7. IOS开发之自定义键盘

     本文转载至 http://blog.csdn.net/majiakun1/article/details/41242069 实际开发过程中,会有自定义键盘的需求,比如,需要添加一个表情键盘.本文提供 ...

  8. IOS自定义日历控件的简单实现(附思想及过程)

    因为程序要求要插入一个日历控件,该空间的要求是从当天开始及以后的六个月内的日历,上网查资料基本上都说只要获取两个条件(当月第一天周几和本月一共有多少天)就可以实现一个简单的日历,剩下的靠自己的简单逻辑 ...

  9. iOS关闭键盘的两种简单方法

    方法一: //1     [[[UIApplication sharedApplication] keyWindow] endEditing:YES]; ,为了关闭弹出的软键盘要遍历然后调用resig ...

随机推荐

  1. monkeyrunner初试

    Monkeyrunner学习心得 在网上下载并且配置好python,androidsdk和jdk的环境之后,在cmd中运行一下python,java -vesion和monkeyrunner,使之都可 ...

  2. Gin框架中文文档

    Gin 是一个 go 写的 web 框架,具有高性能的优点.官方地址:https://github.com/gin-gonic/gin 带目录请移步 http://xf.shuangdeyu.com/ ...

  3. 启动elasticsearch-head显示集群健康值:未连接

    ES启动后,进行es header访问的话,使用localhost:9100会显示集群健康值未连接 2种情况(均为windows10环境下): 1:未在elasticsearch-6.8.0\conf ...

  4. 华为HCNA乱学Round 2:路由基础

  5. 微信小程序request请求封装,验签

    1/ 公共文件util添加 request请求 //简单封装请求 function request(params, path, isShowLoading = true, goBack = false ...

  6. 暴力破解-DVWA_1.9-笔记

     穷举法  通过社工尽可能的缩小密码字典的范围   所用到的工具: Firefox浏览器及其插件Proxy Switcher, OWASP ZAP代理抓包工具. OWASP ZAP  代理抓包工具 h ...

  7. MySQL数据库的常见操作

    1.查看所有的数据库 1 show databases; 2.创建数据库  后面的时编码格式 1 create database dbName charset='utf8'; 3.使用/切换数据库 1 ...

  8. Elasticsearch-集群增加节点

    ES-在集群中加入节点 查看分片信息 FengZhendeMacBook-Pro:nacos FengZhen$ curl 'localhost:9200/_cat/shards?v' index s ...

  9. Spring MVC 跳转页面的方法

    转一个Spring MVC 跳转页面的方法,楼主总结的很全面,留着备用. https://blog.csdn.net/c_royi/article/details/78528758

  10. mysql查看锁查看

    关键词:mysql锁争用,mysql锁查看 --------------------- 作者:边城cn 来源:CSDN 原文:https://blog.csdn.net/miyatang/articl ...