【发布时间】:2012-11-20 07:30:30
【问题描述】:
您好,我有一个带有文本的文本视图,我想在开始时移动光标位置我使用了 NSMakeRange,但我不知道为什么它不起作用。我写过 NSMakeRange is different places ,希望它至少能运行一次但没有用。这是代码。提前谢谢
- (void)viewDidLoad
{
[super viewDidLoad];
apnatxtView.textColor=[UIColor lightGrayColor];
apnatxtView.text=@"Description goes here";
totalLenght=apnatxtView.text.length;
apnatxtView.selectedRange=NSMakeRange(0,0);
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
apnatxtView.selectedRange=NSMakeRange(0,0);
return YES;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[apnatxtView resignFirstResponder];
}
- (void)textViewDidChange:(UITextView *)textView{
if (apnatxtView.text.length == 0) {
apnatxtView.textColor= [UIColor lightGrayColor];
apnatxtView.text=@"Description goes here";
apnatxtView.selectedRange=NSMakeRange(0, 0);
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
if (apnatxtView.textColor == [UIColor lightGrayColor]) {
apnatxtView.textColor=[UIColor blackColor];
// apnatxtView.text=@"Description goes here";
apnatxtView.text=nil;
return YES;
}
}
【问题讨论】:
-
@CodaFi
UITextField和UITextView不一样,同样的代码可能不行。 -
也许 TwUI 正在腐蚀我的大脑......
标签: ios uitextview