一:编辑被键盘遮挡的问题

参考自:http://blog.csdn.net/windkisshao/article/details/21398521

1.自定方法 ,用于移动视图

-(void)moveInputBarWithKeyboardHeight:(float)_CGRectHeight withDuration:(NSTimeInterval)_NSTimeInterval;

2.注册监听

NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];

[defaultCenter selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];

[defaultCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];

3.实现方法

- (void)keyboardWillShow:(NSNotification *)notification {

NSDictionary *userInfo = [notification userInfo];

NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];

CGRect keyboardRect = [aValue CGRectValue];

NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

NSTimeInterval animationDuration;

[animationDurationValue getValue:&animationDuration];

if(nil==self.myTextView) return;//    self.editTextView 为被键盘遮挡住的控件

CGRect rect = self.myTextView.frame;

float textY = rect.origin.y + rect.size.height;

float bottomY = SCREENHEIGHT - textY;//得到下边框到底部的距离  SCREENHEIGHT 为当前设备的高度

if(bottomY >=keyboardRect.size.height ){//键盘默认高度,如果大于此高度,则直接返回

return;

}

float moveY = keyboardRect.size.height - bottomY;

[self moveInputBarWithKeyboardHeight:moveY withDuration:animationDuration];

}

- (void)keyboardWillHide:(NSNotification *)notification {

NSDictionary* userInfo = [notification userInfo];

NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];

NSTimeInterval animationDuration;

[animationDurationValue getValue:&animationDuration];

[self moveInputBarWithKeyboardHeight:0.0 withDuration:animationDuration];

}

-(void)moveInputBarWithKeyboardHeight:(float)_CGRectHeight withDuration:(NSTimeInterval)_NSTimeInterval{

CGRect rect1 = self.view.frame;

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:_NSTimeInterval];

rect1.origin.y = -_CGRectHeight;//view往上移动

self.view.frame = rect1;

[UIView commitAnimations];

}

二: 键盘

(1)键盘类型

UIKeyboardTypeDefault, // 默认键盘:支持所有字符

  1. UIKeyboardTypeASCIICapable, // 支持ASCII的默认键盘
  2. UIKeyboardTypeNumbersAndPunctuation, // 标准电话键盘,支持+*#等符号
  3. UIKeyboardTypeURL, // URL键盘,有.com按钮;只支持URL字符
  4. UIKeyboardTypeNumberPad,  //纯数字键盘 (不带小数点)
  5. UIKeyboardTypeDecimalPad  //数字键盘 (带小数点)
  6. UIKeyboardTypePhonePad,   // 电话键盘
  7. UIKeyboardTypeNamePhonePad, // 电话键盘,也支持输入人名字
  8. UIKeyboardTypeEmailAddress, // 用于输入电子邮件地址的键盘
  9. UIKeyboardTypeWebSearch     //用于搜索
  10. UIKeyboardTypeAlphabet

如:  self.uIphone.keyboardType = UIKeyboardTypeNumberPad;

祥见:http://blog.csdn.net/crazyzhang1990/article/details/39965931

(2) return键的类型

UIReturnKeyDefault, 默认 灰色按钮,标有Return

  UIReturnKeyGo,     标有Go的蓝色按钮           (完成,可用于填写资料的最后一项)

   UIReturnKeyGoogle,标有Google的蓝色按钮,用语搜索

   UIReturnKeyJoin,标有Join的蓝色按钮

    UIReturnKeyNext,标有Next的蓝色按钮             (可用于登录/注册/填写地址-->下一步)

    UIReturnKeyRoute,标有Route的蓝色按钮

    UIReturnKeySearch,标有Search的蓝色按钮     (可用于搜索)

    UIReturnKeySend,标有Send的蓝色按钮

   UIReturnKeyYahoo,标有Yahoo的蓝色按钮

    UIReturnKeyYahoo,标有Yahoo的蓝色按钮

    UIReturnKeyEmergencyCall, 紧急呼叫按钮

如:

self.uIphone.keyboardType = UIKeyboardTypeNumberPad;

(3) 点击return建响应事件

A.UITextField --> - (BOOL)textFieldShouldReturn:(UITextField *)textField{

如:  添加地址

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

if(textField.tag==10)  //下一步 (姓名)

{

[self.uName resignFirstResponder];

[self.uIphone becomeFirstResponder];

}else if(textField.tag==11)   //下一步 (电话)

{

[self.uIphone resignFirstResponder];

[self.reciveAddress becomeFirstResponder];

}else if(textField.tag==100)   //完成(地址填完之后可直接调用接口)

{

[self.reciveAddress resignFirstResponder];

[self addBtn:nil];

}

return YES;

}

B.UITextView --> - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

如:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){ //判断输入的字是否是回车,即按下return
        //在这里做你响应return键的代码

[self addBtn:nil];

        return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行
    }

return YES;
}

参考自:http://blog.sina.com.cn/s/blog_59fb90df010176re.html

三:UITextField小结

1.自定义UITextField 左边加图标(如:登录)

UIImageView *i=[[UIImageView alloc]initWithFrame:CGRectMake(15, 10, 21, 21)];

[i setImage:[UIImage imageNamed:@"yh"]];

UIView *userLeftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 40, 38)];

[userLeftView addSubview:i];

self.userName.leftView=userLeftView;

self.userName.leftViewMode=UITextFieldViewModeAlways;

2.设置自定义UITextField 的Placeholder颜色

UIColor *color = [UIColor blue];

self.userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"  手机号" attributes:@{NSForegroundColorAttributeName: color}];

四:UITextView小结

1.设置Placeholder

@property (nonatomic,strong) UILabel  *proText1;

self.automaticallyAdjustsScrollViewInsets = NO;

[self.leaveMessage setDelegate:self];

UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(self.leaveMessage.frame.origin.x+10, self.leaveMessage.frame.origin.y-35, self.leaveMessage.bounds.size.width, 100)];

lbl.text=@" 感谢您留下宝贵的意见....";

[lbl setFont:[UIFont systemFontOfSize:15.0]];

lbl.enabled=NO;

self.proText1=lbl;

[self.view addSubview:lbl];

#pragma mark -----textView的代理事件

-(void)textViewDidChange:(UITextView *)textView

{

//  textView.text = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if (textView.text.length == 0) {

self.proText1.text = @" 感谢您留下宝贵的意见....";

}else{

self.proText1.text = @"";

}

}

2.去掉空格以及换行

NSString *content = [textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

有的时候由于不正确的操作,直接将textView.text作为参数传 到服务器,可能会产生意想不到的错误,因此就需要加这个对字符串进行一下处理

更多请参考:http://www.41443.com/HTML/iphone/20141109/204260.html

iOS 之UITextFiled/UITextView小结的更多相关文章

  1. ios 浅谈一下UITextFiled UITextView 在tableview的cell上边展示

    最近在项目中.要做到在tableview的cell上边加一个输入框.允许用户输入. 1.我首先选的是在uitextView  然后在通知键盘出现的时候,将tableview的内容设置在键盘的上边.但是 ...

  2. ios学习开发阶段小结

    总结一下,开发了1个月10天的ios经验. 先晒成绩单:两个实验性质的app,一个wifi管家,一个图片壁纸软件 技术小结: 1.熟悉基本的各种ns语法:#import,#include,@class ...

  3. iOS开发-UITextView文字排版

    UITextView文本排版 1.配置NSMutableParagraphStyle NSMutableParagraphStyle *MParaStyle = [[NSMutableParagrap ...

  4. IOS开发,知识点小结,ios开发中经常使用的宏定义总结

    IOS开发,从应用跳转到用浏览器打开网页: [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http:// ...

  5. Unity3D在IOS上的优化小结

    http://www.58player.com/blog-635-122.html 最近一段時間一直在做Unity 在IOS設備上的資源優化,結合Unity的官方文檔以及自己遇到的實際問題,我把自己認 ...

  6. iOS——数据安全性问题小结

    在移动互联网快速发展的今天,iOS应用直接运行在用户的手机上,与运行在服务器后台服务相比,更有可能被黑客攻击. a.网络安全: 1.1 安全地传输用户密码 事先生成一对用于加密的公私钥,客户端登录的时 ...

  7. IOS开发之—— UITextView禁止Emoji输入

    UITextView代理方法:判断 -(void)textViewDidEndEditing:(UITextView *)textView{        if ([self stringContai ...

  8. iOS开发之UITextView,设置textView的行间距及placeholder

    一.设置textView的行间距 1.如果只是静态显示textView的内容为设置的行间距,执行如下代码: //    textview 改变字体的行间距     NSMutableParagraph ...

  9. iOS开发——设备信息小结(未完待续...)

    1.获取设备的信息  UIDevice *device = [[UIDevice alloc] init]; NSString *name = device.name;       //获取设备所有者 ...

随机推荐

  1. Apache Ignite之集群应用测试

    集群发现机制 在Ignite中的集群号称是无中心的,而且支持命令行启动和嵌入应用启动,所以按理说很简单.而且集群有自动发现机制感觉对于懒人开发来说太好了,抱着试一试的心态测试一下吧. 在Apache ...

  2. 【趣事】用 JavaScript 对抗 DDOS 攻击 (下)

    上一篇:http://www.cnblogs.com/index-html/p/js-network-firewall.html 对抗 v2 之前的那些奇技淫巧,纯属娱乐而已,并不能撑多久. 但简单. ...

  3. 我们是怎么做Code Review的

    前几天看了<Code Review 程序员的寄望与哀伤>,想到我们团队开展Code Review也有2年了,结果还算比较满意,有些经验应该可以和大家一起分享.探讨.我们为什么要推行Code ...

  4. java head space/ java.lang.OutOfMemoryError: Java heap space内存溢出

    上一篇JMX/JConsole调试本地还可以在centos6.5 服务器上进行监控有个问题端口只开放22那么设置的9998端口 你怎么都连不上怎么监控?(如果大神知道还望指点,个人见解) 线上项目出现 ...

  5. Cocos2d Android 环境搭建

    1.在开始之前,需要先准备好资源如下,如果安卓开发环境有了直接装第3.4. 1.JDK      点击下载 (1.6) 2.ADT(已经自带Android SDK)点击下载 3.NDK 点击下载 4. ...

  6. C++中的引用

    一,C++中引用的基础知识 1.引用的基本概念 1.所谓的引用其实就是对变量起“别名”.引用和变量对应得是相同的内存,修改引用的值,变量的值也会改变,和指针类似. 2.引用在定义的时候必须要初始化,初 ...

  7. Hawk 6. 高级话题:子流程系统

    子流程的定义 当流程设计的越来越复杂,越来越长时,就难以进行管理了.因此,采用模块化的设计才会更加合理.本节我们介绍子流程的原理和使用. 所谓子流程,就是能先构造出一个流程,然后被其他流程调用.被调用 ...

  8. nodejs操作arduino入门(javascript操作底层硬件)

    用Javascript来操作硬件早就不是一件稀奇的事情了. 所以作为一名电子专业出身的FE,我也打算尝试一下用js来驱动arduino: 要想操作这些底层硬件,肯定是需要一些工具的,我这里介绍的工具主 ...

  9. HTML5 Page Visibility

    什么是 Page Visibility ? Page Visibility 即页面可见性,通过 visibilityState 的值检测页面当前是否可见.当一个网站是可见或点击选中的状态时 Page ...

  10. Register-SPWorkflowService 404

    最近需要做一个SharePoint 2013工作流演示环境. 于是在自己的本子上安装了一个虚拟机. 虚拟机操作系统是Windows Server 2012 R2,计划把AD.SQL Server 20 ...