iPhone开发--光标定位到含有文字的UITextVIew的首位置
建立一个UITextView,默认启动键盘,并将光标定位到首位置,因为UITextFiled类没有此功能,所以改用UItextView.
代码如下:
[cpp] UITextView *m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField.frame = CGRectMake(0, 0, 320, 90) ;
m_contentTextField.backgroundColor = [UIColor whiteColor] ;
m_contentTextField.font = [UIFont systemFontOfSize:14];
m_contentTextField.delegate = self ;
UITextView *m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField = [[[UITextView alloc] init] autorelease];
m_contentTextField.frame = CGRectMake(0, 0, 320, 90) ;
m_contentTextField.backgroundColor = [UIColor whiteColor] ;
m_contentTextField.font = [UIFont systemFontOfSize:14];
m_contentTextField.delegate = self ;
设置此UITextView为第一响应者,www.2cto.com 即默认打开键盘。
[cpp] [m_contentTextField becomeFirstResponder];
[m_contentTextField becomeFirstResponder];当UITextView中含有文字时,系统默认将光标定位到最后的位置,下面的语句将光标定位到首位置。
[cpp] m_contentTextField.selectedRange = NSMakeRange(0,0);
摘自 zcl369369的专栏
相关新闻>>
- 发表评论
-
- 最新评论 更多>>
今日头条
更多>>您可能感兴趣的文章
- iPhone应用开发之十一:常用的三种动画表现效果
- ios学习笔记(二)xcode 4.3.2下实现基本交互
- ios开发问题:添加库和复制其它工程文件编译错误问题
- Memory on the iPhone
- 多线程之NSInvocationOperation
- Android:实现TabWidget选项卡按钮在屏幕下方
- iphone开发之object c基础一定义接口
- (iPhone/iPad开发)presentViewController相应方法在SDK5.0前后
- Lexical or Preprocessor Issue 'xxx.h
- iPhone开发学习笔记006—— NSNotification自定义通知名