自定义文本框:

#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截屏方法

    //获取屏幕截屏方法 - (UIImage *)capture { // 创建一个context UIGraphicsBeginImageContextWithOptions(self.view.bo ...

  2. mono touch登录设计

    需要对MonoTouch.Dialog-1进行引用: using System; using System.Collections.Generic; using System.Linq; using ...

  3. Ext4中获取下拉框的值

    var supplierCombo = Ext.getCmp("rkSupplierCombo_id");  var supplierId = supplierCombo.getV ...

  4. 添加 jar 包后需要做的配置

  5. Kafka:ZK+Kafka+Spark Streaming集群环境搭建(七)针对hadoop2.9.0启动DataManager失败问题

    DataManager启动失败 启动过程中发现一个问题:slave1,slave2,slave3都是只启动了DataNode,而DataManager并没有启动: [spark@slave1 hado ...

  6. innerWidth outerWidth

    在jQuery中: 一.width()方法用于获得元素宽度: 二.innerWidth()方法用于获得包括内边界(padding)的元素宽度; 三.outerWidth()方法用于获得包括内边界(pa ...

  7. .Net Framework System.Collections 集合类

    本文内容 集合类 性能 最近复习了一下集合,C# 关于集合的类蛮多,但我除了 List 那几个经常用之外,其他的用得还真不多(只在小范围使用),但其实,每个集合类都各有自己适用的场景,功能也很强大.尤 ...

  8. SVN 配置文件说明

    svnserve是SVN自带的一个轻型服务器,客户端通过使用以svn://或svn+ssh://为前缀的URL来访问svnserve服务器,实现远程访问SVN版本库.svnserve可以通过配置文件来 ...

  9. MySQL 存储过程/游标/事务

    将会用到的几个表 mysql> DESC products; +------------+--------------+------+-----+---------+-------------- ...

  10. 1050: 贝贝的ISBN号码(isbn)

    #include <iostream> #include <iomanip> #include <cstdlib> #include <string> ...