重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

代码讲解IOS键盘响应和处理

本篇文章展示了IOS键盘响应和处理的具体操作,代码应该是足够清楚的,而且我也相信有相当的一些例子可能是我们日常工作可能会见得到的。通过这些问题,希望你能收获更多。

创新互联专注于成都网站设计、做网站、网页设计、网站制作、网站开发。公司秉持“客户至上,用心服务”的宗旨,从客户的利益和观点出发,让客户在网络营销中找到自己的驻足之地。尊重和关怀每一位客户,用严谨的态度对待客户,用专业的服务创造价值,成为客户值得信赖的朋友,为客户解除后顾之忧。

一个简单的登录功能,遇到最大的问题就是怎么处理弹出的键盘,如何让它下去,这是一个首先要处理的问题。

 

ViewController.h:

#import   @interface DXWViewController : UIViewController  - (IBAction)OKClick:(id)sender; - (IBAction)cancleClick:(id)sender; @property (retain, nonatomic) IBOutlet UILabel *label; - (IBAction)end:(id)sender;//键盘退出方法 @property (retain, nonatomic) IBOutlet UITextField *name; @property (retain, nonatomic) IBOutlet UITextField *password;  @end


 
 

ViewController.m:

#import "DXWViewController.h"  @interface DXWViewController ()  @end  @implementation DXWViewController  - (void)viewDidLoad {     [super viewDidLoad];     //view一加载就让输入框成为第一响应者     [self.name becomeFirstResponder]; }  - (void)didReceiveMemoryWarning {     [super didReceiveMemoryWarning]; }  - (IBAction)OKClick:(id)sender {     NSString *strName = self.name.text;     NSString *strPwd = self.password.text;     self.label.text = [NSString stringWithFormat:@"姓名:%@,密码:%@",strName,strPwd];     //根据字的长度来设置label的大小,而不是用autolayerout来实现     CGSize size = [self.label.text sizeWithFont:self.label.font];     CGRect frame = CGRectMake(self.label.frame.origin.x,self.label.frame.origin.y, size.width, self.label.frame.size.height);     self.label.frame = frame; }  - (IBAction)cancleClick:(id)sender { } - (void)dealloc {     [_label release];     [_name release];     [_password release];     [super dealloc]; } - (IBAction)end:(id)sender {     [self.name resignFirstResponder];     [self.password resignFirstResponder]; } @end 

看完上诉内容,你们掌握IOS键盘响应和处理的方法了吗?如果想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


当前题目:代码讲解IOS键盘响应和处理
网站路径:http://cqcxhl.com/article/jdeoed.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP