Powiel możliwe:
Placeholder in UITextViewJak dodać placeHolder Text w UItextView? w iPhone SDK
w iPhone App Jak dodać tekst zastępczy (by zatrzymać jakiś tekst domyślny) w UItextView
?
Powiel możliwe:
Placeholder in UITextViewJak dodać placeHolder Text w UItextView? w iPhone SDK
w iPhone App Jak dodać tekst zastępczy (by zatrzymać jakiś tekst domyślny) w UItextView
?
Proste, zrobiłem to w ten sposób .. działa doskonale dla mnie .. Nadzieja to pomaga kogoś ..
#pragma mark -
#pragma mark TextView Delegate methods
UITextView itsTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, itsTextView.frame.size.width, itsTextView.frame.size.height)];
[itsTextView setDelegate:self];
[itsTextView setReturnKeyType:UIReturnKeyDone];
[itsTextView setText:@"List words or terms separated by commas"];
[itsTextView setFont:[UIFont fontWithName:@"HelveticaNeue" size:11]];
[itsTextView setTextColor:[UIColor lightGrayColor]];
- (BOOL) textViewShouldBeginEditing:(UITextView *)textView
{
if (itsTextView.textColor == [UIColor lightGrayColor]) {
itsTextView.text = @"";
itsTextView.textColor = [UIColor blackColor];
}
return YES;
}
-(void) textViewDidChange:(UITextView *)textView
{
if(itsTextView.text.length == 0){
itsTextView.textColor = [UIColor lightGrayColor];
itsTextView.text = @"List words or terms separated by commas";
[itsTextView resignFirstResponder];
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
if(itsTextView.text.length == 0){
itsTextView.textColor = [UIColor lightGrayColor];
itsTextView.text = @"List words or terms separated by commas";
[itsTextView resignFirstResponder];
}
return NO;
}
return YES;
}
Zawarłem powyższy kod, ale podczas edytowania didbegin usuwa znak zastępczy, ale w viewdidchange zawsze umieszcza symbol zastępczy, aby użytkownik nie mógł edytować/wpisać w tekście jest dowolny rozwiązanie – krishh
Hai @ sugan.s Domyślam się, że nie ustawiasz koloru tekstu jako '[itsTextView setTextColor: [UIColor lightGrayColor]];' –
Jak widać usuwamy tekst w oparciu o kolor tekstu .. daj mi znać, jeśli to pomoże .. –
Proszę edytować swoje pytanie z wyjaśnieniem, co masz na myśli przez „zastępczy” –
Będzie help you: http://stackoverflow.com/a/17451491/1442541 – evya