建立一个UITextView,默认启动键盘,并将光标定位到首位置,因为UITextFiled类没有此功能,所以改用UItextView.
代码如下:
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 becomeFirstResponder];当UITextView中含有文字时,系统默认将光标定位到最后的位置,下面的语句将光标定位到首位置。m_contentTextField.selectedRange = NSMakeRange(0,0);
参考文献:https://discussions.apple.com/message/12209784#12209784
本文介绍如何使用Swift或Objective-C来设置UITextView,使其在应用启动时自动显示键盘并将光标定位在文本编辑区的起始位置。适用于需要快速进入文本输入状态的应用场景。

被折叠的 条评论
为什么被折叠?



