---
title: "关于textView,textField及delegate的使用"
author: "chenjohney"
date: "2011-12-14T23:02:34Z"
tags: []
categories: ["移动开发"]
slug: "textview-textfield-delegate"
draft: false
lastmod: "2012-01-10T01:52:54Z"
id: 1311012
url: "https://chenjohney.iteye.com/blog/1311012"
---

打开键盘

\[textfield becomeFirstResponder];

 

关闭键盘

\[textField resignFirstResponder];

 

```
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange*)range replacementString:(NSString *)string 
```

 

### 此方法在编辑时调用，string表示编辑时选中的文本，，range表示选中的文本的范围， 返回真表示继续编辑，返回假表示放弃当前选中的内容。 因为在textfield输入的时候分为两个部分 比如以下带阴影的就是正在编辑的文本   input stri textfield.text 为input string 为 stri