ios中修改数字键盘
自定义文本框:
#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中修改数字键盘的更多相关文章
- IOS中修改图片的大小:修改分辨率和裁剪
在IOS开发中,经常有限制图片文件大小的,有的用户图片很大,导致上传时间慢,造成问题. 如:微信分享中,如果图片的大小好像大于50kbytes,就分享失败,而且没有任何提示. 所以,我添加了两个函数: ...
- iOS中监控软键盘显示或隐藏的可靠方法
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 如果你试图在软键盘的显示或隐藏时去改变的UI界面结构,仅有的方 ...
- 【转】iOS中修改AVPlayer的请求头信息
在开发中, 我们经常需要在网络请求时修改HTTP/HTTPS的请求头信息 1.普通AFN请求 #import "LMHTTPSessionManager.h" #import &l ...
- ios中怎么处理键盘挡住输入框
//此前要遵循UITextFieldDelegate代理.并且设置该文本框为当前控制器的代理 //开始编辑的时候让整个view的高度网上移动 - (void)textFieldDidBeginEdit ...
- iOS中修改头部tabBarButton 默认按钮的颜色和默认字体颜色
+(void)initialize { //初始化设置主题 UINavigationBar *navBar = [UINavigationBar appearance]; [navBar setBac ...
- 【笔记】移动端H5数字键盘input type=number的处理(IOS和Android)
在Vue中的项目,基于VUX-UI开发,一个常见的需求: 1.金额输入框 2.弹出数字键盘 3.仅支持输入两位小数,限制最大11位数,不允许0开头 后续:与UI沟通后, 思路调整为限制输入,并减少正则 ...
- iOS中 H5的input输入框focus()无法自动拉起键盘(解决方法)
ios的hybird APP 无法使用focus()获取焦点和键盘的问题. 解决方案 原来,在App的配置文件(config.xml),里面默认会有一句 1 <preference name=& ...
- VirtualBox中出现UUID have already exists ,并且数字键盘numlock效果相反
原文地址:https://www.cnblogs.com/xqzt/p/5053338.html 原因:由于linux密码登录错误,修改也报错误,所以只能重新安装虚拟机并在其中安装镜像文件,但是安装镜 ...
- iOS 系统数字键盘左下角加确定按钮
首先在 viewWillAppear 方法中注册监听相应的键盘通知,并且要在 viewWillDisappear 方法中注销通知- (void)viewWillAppear:(BOOL)animate ...
随机推荐
- 东芝发布运行Win 10的AR眼镜,它和Google Glass企业版有哪些异同?
https://www.leiphone.com/news/201803/Tw0nrq6vGDIvbmXr.html 雷锋网(公众号:雷锋网)获悉,3月13日,东芝发布新AR眼镜dynaEdge AR ...
- win8 中如何删除 共享文件夹 用户名和密码
在访问共享文件夹时我们都喜欢选中记住用户名和密码,可是有时候密码输入错误或者密码修改了,这时就需要我们删除或则修改先前记住的用户名和密码记录. 首先进入:控制面板\所有控制面板项\凭据管理器 选择wi ...
- css 下边框
float: left; width: 1200px; height: 42px; background-color: #fff0; /* background-color: #4f4aff; */ ...
- ASP.NET MVC 基于页面的权限管理
菜单表 namespace AspNetMvcAuthDemo1.Models { public class PermissionItem { public int ID { set; get; } ...
- JAVA Eclipse如何导入已有的项目
File-Import,然后在弹出的窗口中输入exit,会自动提示下面的选项(已存在的项目) 把项目源代码放到Eclipse的工作目录,然后找到 导入完成
- Android [VP]视频播放器播放本地视频时收到短信/彩信,需要界面提示 M
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- How to check WWN and Multipathing on Windows Server
There are many ways to find the World Wide Name (WWN) of fibre channel HBA connected to windows serv ...
- oj
https://github.com/zhblue/hustoj insert into privilege(user_id,rightstr) values('wxy','administrator ...
- springboot整合mybatis的两种方式
https://blog.csdn.net/qq_32719003/article/details/72123917 springboot通过java bean集成通用mapper的两种方式 前言:公 ...
- jmap 命令
1. jmap -heap pid 查看java 堆(heap)使用情况 using thread-local object allocation. ...