自定义文本框:

#import <UIKit/UIKit.h>

//自定义键盘的键定义
@interface DIYKey : NSObject
{
}
@property(copy, nonatomic) NSString* name;
@property(copy, nonatomic) NSString* representedString;
@property(copy, nonatomic) NSString* displayString;
@property(copy, nonatomic) NSString* displayType;
@property(copy, nonatomic) NSString* interactionType;
@property(copy, nonatomic) NSString* variantType;
@property(assign, nonatomic) BOOL visible;
@property(assign, nonatomic) unsigned displayTypeHint;
@property(retain, nonatomic) NSString* displayRowHint;
@property(copy, nonatomic) NSArray* variantKeys;
@property(copy, nonatomic) NSString* overrideDisplayString;
@property(assign, nonatomic) BOOL disabled;
@property(assign, nonatomic) BOOL hidden;
@end ////自定义键盘的视图
@interface DIYKeyView : UIView
{
}
@property(readonly, assign, nonatomic) DIYKey* key;
@end @protocol MJTextFieldDelegate; @interface MJTextField : UITextField @property(nonatomic,assign)id<MJTextFieldDelegate> MjDelegate;
@property(nonatomic,retain) UIButton* sureButton;
-(DIYKeyView *)FindView:(NSString *)name;
-(void )addCustormButton:(NSString *)name title:(NSString *)title target:(id)target action:(SEL)action;
-(void)delCustormButton;
-(void )modifyKeyView:(NSString *)name display:(NSString *)display represent:(NSString *)represent interaction:(NSString *)type;
@end @protocol MJTextFieldDelegate <NSObject>
-(void)keyBoardShow:(MJTextField *)textField;
-(void)keyboardHide:(MJTextField *)textField; @end
#import "MJTextField.h"

@implementation MJTextField

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} -(BOOL)resignFirstResponder{
BOOL ret=[super resignFirstResponder];
if(self.MjDelegate){
[self.MjDelegate keyboardHide:self];
} return ret;
} -(BOOL)becomeFirstResponder{
BOOL ret=[super becomeFirstResponder];
if(self.MjDelegate){
[self.MjDelegate keyBoardShow:self];
}
return ret;
} #pragma mark -find view -(DIYKeyView *)FindKeyView:(NSString *)name inView:(UIView *)view{
for (DIYKeyView *subview in view.subviews)
{ NSString *className = NSStringFromClass([subview class]); if ([className isEqualToString:@"UIKBKeyView"])
{
NSLog(@"name-->%@",subview.key.name);
if((name==nil)||[subview.key.name isEqualToString:name])
return subview; }
else
{
DIYKeyView *subview2 = [self FindKeyView:name inView:subview];
if (subview2!=nil) {
return subview2;
} }
}
return nil; } -(DIYKeyView *)FindView:(NSString *)name{
UIWindow* window = [[[UIApplication sharedApplication] windows] objectAtIndex:];
return [self FindKeyView:name inView:window]; } //添加键
-(void )addCustormButton:(NSString *)name title:(NSString *)title target:(id)target action:(SEL)action{
//先找到指定的键盘
DIYKeyView *view=[self FindView:name];
if(view){
self.sureButton=[[UIButton alloc] initWithFrame:view.frame];
self.sureButton.titleLabel.font=[UIFont boldSystemFontOfSize:];
[self.sureButton setTitle:title forState:UIControlStateNormal];
[self.sureButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
[self.sureButton setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self.sureButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
self.sureButton.showsTouchWhenHighlighted=YES;
[view.superview addSubview:self.sureButton];
} } //删除键
-(void)delCustormButton{
if(self.sureButton){
[self.sureButton removeFromSuperview];
self.sureButton=nil;
}
} //修改键盘
-(void )modifyKeyView:(NSString *)name display:(NSString *)display represent:(NSString *)represent interaction:(NSString *)type{
DIYKeyView *view=[self FindView:name];
if(view){
view.key.displayString=display;//键盘显示的内容
view.key.representedString=represent;//点击键盘,输入的内容
if(type){
view.key.displayType=type;
}
[view setNeedsDisplay];
}
} @end
#import <UIKit/UIKit.h>
#import "MJTextField.h" @interface ViewController : UIViewController<MJTextFieldDelegate>
- (IBAction)click:(id)sender;
@property (retain, nonatomic) IBOutlet UITextField *text; @end #import "ViewController.h" @interface ViewController () @end @implementation ViewController #pragma mark -生命周期方法
- (void)viewDidLoad
{
[super viewDidLoad];
MJTextField *mj=[[MJTextField alloc] initWithFrame:CGRectMake(, , , )];
mj.borderStyle=UITextBorderStyleRoundedRect;
mj.keyboardType=UIKeyboardTypeNumberPad;
mj.tag=;
mj.MjDelegate=self;
[self.view addSubview:mj];
[mj release]; MJTextField *mj1=[[MJTextField alloc] initWithFrame:CGRectMake(, , , )];
mj1.borderStyle=UITextBorderStyleRoundedRect;
mj1.keyboardType=UIKeyboardTypeDefault;
mj1.MjDelegate=self;
mj1.tag=;
mj1.returnKeyType=UIReturnKeyDone;
[self.view addSubview:mj1];
[mj1 release]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} -(void)keyBoardShow:(MJTextField *)textField{ // Let's crazy!
if(==textField.tag){
[textField modifyKeyView:@"NumberPad-1" display:@"x" represent:@"aa" interaction:nil]; } }
-(void)keyboardHide:(MJTextField *)textField{
[textField delCustormButton];
} - (void)dealloc
{ [super dealloc];
} -(void)myclick:(id)sender{
NSLog(@"aa");
} -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];
} @end

ios中修改数字键盘的更多相关文章

  1. IOS中修改图片的大小:修改分辨率和裁剪

    在IOS开发中,经常有限制图片文件大小的,有的用户图片很大,导致上传时间慢,造成问题. 如:微信分享中,如果图片的大小好像大于50kbytes,就分享失败,而且没有任何提示. 所以,我添加了两个函数: ...

  2. iOS中监控软键盘显示或隐藏的可靠方法

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 如果你试图在软键盘的显示或隐藏时去改变的UI界面结构,仅有的方 ...

  3. 【转】iOS中修改AVPlayer的请求头信息

    在开发中, 我们经常需要在网络请求时修改HTTP/HTTPS的请求头信息 1.普通AFN请求 #import "LMHTTPSessionManager.h" #import &l ...

  4. ios中怎么处理键盘挡住输入框

    //此前要遵循UITextFieldDelegate代理.并且设置该文本框为当前控制器的代理 //开始编辑的时候让整个view的高度网上移动 - (void)textFieldDidBeginEdit ...

  5. iOS中修改头部tabBarButton 默认按钮的颜色和默认字体颜色

    +(void)initialize { //初始化设置主题 UINavigationBar *navBar = [UINavigationBar appearance]; [navBar setBac ...

  6. 【笔记】移动端H5数字键盘input type=number的处理(IOS和Android)

    在Vue中的项目,基于VUX-UI开发,一个常见的需求: 1.金额输入框 2.弹出数字键盘 3.仅支持输入两位小数,限制最大11位数,不允许0开头 后续:与UI沟通后, 思路调整为限制输入,并减少正则 ...

  7. iOS中 H5的input输入框focus()无法自动拉起键盘(解决方法)

    ios的hybird APP 无法使用focus()获取焦点和键盘的问题. 解决方案 原来,在App的配置文件(config.xml),里面默认会有一句 1 <preference name=& ...

  8. VirtualBox中出现UUID have already exists ,并且数字键盘numlock效果相反

    原文地址:https://www.cnblogs.com/xqzt/p/5053338.html 原因:由于linux密码登录错误,修改也报错误,所以只能重新安装虚拟机并在其中安装镜像文件,但是安装镜 ...

  9. iOS 系统数字键盘左下角加确定按钮

    首先在 viewWillAppear 方法中注册监听相应的键盘通知,并且要在 viewWillDisappear 方法中注销通知- (void)viewWillAppear:(BOOL)animate ...

随机推荐

  1. iOS开发-类簇(Class Cluster)

    类簇(Class  Cluster)是定义相同的接口并提供相同功能的一组类的集合,仅公开接口的抽象类也可以称之为类簇的公共类,每个具体类的接口有公共类的接口抽象化,并隐藏在簇的内部.这些类一般不能够直 ...

  2. 构建-14 Gradle使用技巧

    官方文档 Gradle 提示与诀窍 [Gradle tips and recipes] Gradle 和 Android Plugin for Gradle 提供了一种灵活的方式[a flexible ...

  3. 糟糕的css用法 1

    现在网站追求越来越漂亮好看,越来越炫,所以css是必不可少的.可是我发现许多人使用css的方式是不对的,至少是不推荐的. 比如下面的css用法不对 (1)一个页面对应一个css文件 这种做法是我深恶痛 ...

  4. 大数据开发实战:Hadoop数据仓库开发实战

    1.Hadoop数据仓库架构设计 如上图. ODS(Operation Data Store)层:ODS层通常也被称为准备区(Staging area),它们是后续数据仓库层(即基于Kimball维度 ...

  5. TRIZ系列-创新原理-13-反过来做原理

    反过来做原理表述例如以下: 1)不直接接实施问题指出的动作,而是实施一个相反的动作;(比方用冷却取代加热等):2) 使物体或外部环境移动的部分精巧.或者使精巧的部分移动:3) 把物体上下颠倒.反过来做 ...

  6. 概率图模型学习笔记:HMM、MEMM、CRF

    作者:Scofield链接:https://www.zhihu.com/question/35866596/answer/236886066来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商 ...

  7. ASP入门(十三)-Server对象

    Server 对象用于处理服务器上的一些特殊任务,例如,创建组件实例.获取文件路径.执行ASP脚本文件等. Server 对象是体现 ASP 强大功能的一个对象,之前介绍的对象都是针对获取.请求以及简 ...

  8. js文件流下载通用方法

    通常我们会用到文件流下载文件,下面给大家一个通用的文件流下载的js /* *下载文件 * options:{ * url:'', //下载地址 * isNewWinOpen:false,是否新窗口打开 ...

  9. javascript学习网址

    教程:JavaScript征途 http://www1.huachu.com.cn/read/readbook.asp?bookid=10109449 教程:JScript 参考 http://msd ...

  10. [工具IDE]工具与书籍

    看到几个还不错的资源,记录于下: 一.使用 JavaScript 写的操作系统: http://www.admin10000.com/document/3811.html 演示地址参考:http:// ...