自定义我的封装键盘,并在试图控制器里对接 (解决多 输入框问题,把输入框存入到可变数组)

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible]; CSKeyBoardViewController * RootVC = [[CSKeyBoardViewController alloc]init];
self.window.rootViewController = RootVC;
[RootVC release];
return YES;
}

main.m

//
// CSKeyBoardViewController.m
//
#import "CSKeyBoardViewController.h"
#import "KeyBoard.h" @interface CSKeyBoardViewController ()<UITextFieldDelegate>
@property(nonatomic,retain)UITextField * tf,*tf1,*tf2;
@property(nonatomic,retain)KeyBoard * keyboard;
@property(nonatomic,retain)NSTimer * timer;
@property(nonatomic,retain)NSMutableArray * tfArr; @end @implementation CSKeyBoardViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. UITextField * textfield = [[UITextField alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )];
NSLog(@"外面%@",textfield);
textfield.placeholder = @"请输入资料";
[self.view addSubview:textfield];
textfield.layer.borderWidth = ;
textfield.layer.cornerRadius = ;
textfield.delegate = self; //如果控制器里有好多的 tf 怎么办 <尚未解决 ????????????????>
// self.timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(textFieldDidBeginEditing:) userInfo:nil repeats:NO];
// 新问题 timer 不知道怎么关闭
UITextField * textfield2 = [[UITextField alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )];
NSLog(@"外面2%@",textfield2);
textfield2.placeholder = @"请输入资料";
[self.view addSubview:textfield2];
textfield2.layer.borderWidth = ;
textfield2.layer.cornerRadius = ;
textfield2.delegate = self; self.tf1 = [[UITextField alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )];
_tf1.placeholder = @"请输入资料";
[self.view addSubview:_tf1];
_tf1.layer.borderWidth = ;
_tf1.layer.cornerRadius = ;
_tf1.delegate = self; self.tf2 = [[UITextField alloc]initWithFrame:CGRectMake(, , self.view.frame.size.width-, )];
_tf2.placeholder = @"请输入资料";
[self.view addSubview:_tf2];
_tf2.layer.borderWidth = ;
_tf2.layer.cornerRadius = ;
_tf2.delegate = self; self.tfArr = [NSMutableArray arrayWithCapacity:];
[_tfArr addObject:textfield];
[_tfArr addObject:textfield2];
[_tfArr addObject:_tf1];
[_tfArr addObject:_tf2]; NSDate * dateNow = [NSDate date];
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * dateString = [formatter stringFromDate:dateNow];
KeyBoard * keyboard = [[KeyBoard alloc]initWithFrame:CGRectMake(, , , ) accessoryText:dateString TextFieledArr:_tfArr];
textfield.inputView = keyboard;
textfield2.inputView = keyboard;
_tf1.inputView = keyboard;
_tf2.inputView = keyboard;
[keyboard release];
[textfield release];
[textfield2 release];
[_tf1 release];
[_tf2 release];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//如果控制器有多个 tf 我们让当前鼠标所在的tf 指向 self.tf
-(void)textFieldDidBeginEditing:(UITextField *)textField{
self.tf = textField; //解决多 tf 问题 (属性)
// self.keyboard = [[KeyBoard alloc]initWithFrame:CGRectMake(0, 150, 375, 240) accessoryText:@"我的键盘" TextFieled:self.tf]; // NSLog(@"如果控制器有多个 tf 我们让当前鼠标所在的tf 指向 self.tf %@------%@",self.tf,textField);
//站换思路 用数组
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"来自视图控制器 移动了鼠标");
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
for (UITextField * tf in self.tfArr) {
[tf resignFirstResponder];
}
[_tf resignFirstResponder];//这里没有什么卵用才用上面的数组释放键盘
NSLog(@"试图控制器回收键盘");
} @end

试图控制器(m)文件 CSKeyBoardViewController.m

#import <UIKit/UIKit.h>

@interface KeyBoard : UIView<UITextFieldDelegate,UIAlertViewDelegate>
//共外界使用的辅助视图
@property(nonatomic,retain)UILabel * accessorView;
//存储当前的输入框
@property(nonatomic,retain)UITextField * tf; /**
* methods for :
外部调用初始化方法创建自定义键盘视图同时可设置辅助视图显示文字 指定为外部输入框的inputView 同时可指定辅助视图(如需)(.accessoryView) 外部操作的输入框需赋值给该类的tf属性
*/ //初始化自定义键盘视图及设置辅助文字方法
//- (instancetype)initWithFrame:(CGRect)frame accessoryText:(NSString *)text
// TextFieled:(UITextField *)textfield; - (instancetype)initWithFrame:(CGRect)frame accessoryText:(NSString *)text
TextFieledArr:(NSMutableArray *)textfieldArr;;
//..待丰富... @end

自定义键盘.h封装好了 KeyBoard.h

//
// KeyBoard.m #define RandomColor [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1.0] #import "KeyBoard.h" @implementation KeyBoard -(instancetype)initWithFrame:(CGRect)frame accessoryText:(NSString *)text TextFieledArr:(NSMutableArray *)textfieldArr{
self = [super initWithFrame:frame];
if (self) {
[self setUpCustomViewWithAccessoryText:text TextFieledArr:textfieldArr];
}
return self;
} -(void)setUpCustomViewWithAccessoryText:(NSString *)accesssoryText
TextFieledArr:(NSMutableArray *)textfieldArr{
NSLog(@"里面%@",textfieldArr);
self.backgroundColor = RandomColor;
for (UITextField * tf in textfieldArr) {//遍历外面的 textfield
tf.delegate = self;
} self.tf.delegate = self;
//键盘辅助视图
self.accessorView = [[UILabel alloc]initWithFrame:CGRectMake(, , self.frame.size.width, )];
_accessorView.backgroundColor = RandomColor;
_accessorView.text = accesssoryText;
_accessorView.textAlignment = NSTextAlignmentCenter;
_accessorView.textColor = RandomColor;
[self addSubview:_accessorView];
//自定义按钮事件
NSArray * KeyArr = @[@[@"",@"",@""],@[@"",@"",@""],@[@"",@"",@""],@[@"✔️", @"", @"

UI:自定义键盘的实现的更多相关文章

  1. UI:登录窗的自定义键盘

    在创建一个自定义键盘的时候遇到的错误 //双重for循环,对于Button上的数字用二维数组 //    NSArray * butArr[4][3] = {@[@"1",@&qu ...

  2. WPF 自定义键盘焦点样式(FocusVisualStyle)

    WPF 自带的键盘焦点样式是与传统控件样式搭配的,但 WPF 凭着其强大的自定义样式的能力,做出与传统控件样式完全不同风格的 UI 简直易如反掌.这时,其自带的键盘焦点样式(FocusVisualSt ...

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

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

  4. 原生HTML5 input type=file按钮UI自定义

    原生<input type="file" name="file" />长得太丑 提升一下颜值 实现方案一.设置input[type=file]透明度 ...

  5. ios 自定义键盘

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

  6. Vue2.0的变化 ,组件模板,生命周期,循环,自定义键盘指令,过滤器

    组件模板: 之前: <template> <h3>我是组件</h3><strong>我是加粗标签</strong> </templat ...

  7. vue.js之过滤器,自定义指令,自定义键盘信息以及监听数据变化

    一.监听数据变化 1.监听数据变化有两种,深度和浅度,形式如下: vm.$watch(name,fnCb); //浅度 vm.$watch(name,fnCb,{deep:true}); //深度监视 ...

  8. swift3.0 自定义键盘

    ...绕了一大圈,又绕回原生来了,今天,学习一下swift3.0语法下的自定义键盘.效果图如下: 其实,很简单,只需要把UITextView(或者UITextField)的inputView属性设置为 ...

  9. vue教程2-08 自定义键盘信息、监听数据变化vm.$watch

    vue教程2-08 自定义键盘信息 @keydown.up @keydown.enter @keydown.a/b/c.... 自定义键盘信息: Vue.directive('on').keyCode ...

随机推荐

  1. windows下用mingw编译linux项目

    1.下载安装mingw32 2.将mingw下bin和msys\1.0下bin设置为系统path 3.启动msys.bat 4.cd到项目目录 5.输入./configure 6.输入make 7.输 ...

  2. hibernate3和spring整合的一些方式

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. [Everyday Mathematics]20150219

    设 $0<a<b$, 试证: $$\bex \int_a^b (x^2+1)e^{-x^2}\rd x\geq e^{-a^2}-e^{-b^2}. \eex$$

  4. selenium python (十)浏览器多窗口处理

    #!/usr/bin/python# -*- coding: utf-8 -*-__author__ = 'zuoanvip'#在测试过程中有时候会遇到出现多个浏览器窗口的情况,这时候我们可以通过窗口 ...

  5. html --- ajax --- javascript --- 简单的封装

    Ajax的简单封装 Ajax的全称是AsynchronousJavaScriptAndXML 如有疑问请参考:http://zh.wikipedia.org/zh-cn/AJAX 以及传智播客的视频教 ...

  6. nagios监控远程主机端口

    1 被监控主机上的操作 修改nrpe插件内容: 在其中增加的内容如下: 表示的含义为监控主机的端口631和661,这个主要是监控命令 重启xinetd服务: 2 监控主机上的操作 查看监控命令配置文件 ...

  7. int型长度

    Ø  基本数据类型 C语言中只有4中基本数据类型——整型.浮点型.指针和聚合类型(如数组和结构等):所有其他类型都是从这4种基本类型的某种变化或组合派生而来. 一.整型家族 整型家族包括char.sh ...

  8. 性能测试-Jmeter

    缘由 很多情况下我们写程序过程中只会对固定模块采取并发限制,而且asp.net对于多线程也有他自己的处理机制,尤其对于注重业务,结果导向的团队可能更注重一定时间节点给出满意的产品,但是你的模块到底是否 ...

  9. 【Python学习笔记】with语句与上下文管理器

    with语句 上下文管理器 contextlib模块 参考引用 with语句 with语句时在Python2.6中出现的新语句.在Python2.6以前,要正确的处理涉及到异常的资源管理时,需要使用t ...

  10. 使用HttpClient实现文件的上传下载

    1 HTTP HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议来访问网络资源. 虽然在 JDK 的 java.net ...