当前位置:编程学习 > wap >>

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.zzzyk.com 即默认打开键盘。


[cpp] [m_contentTextField becomeFirstResponder]; 
[m_contentTextField becomeFirstResponder];当UITextView中含有文字时,系统默认将光标定位到最后的位置,下面的语句将光标定位到首位置。
[cpp] m_contentTextField.selectedRange = NSMakeRange(0,0); 

摘自 zcl369369的专栏

补充:移动开发 , IOS ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,