/ / Ako pridať placeHolder text v UItextView? v iphone sdk [duplikát] - iphone, objekt-c, xcode, ios4, uitextview

Ako pridať text placeHolder do UItextView? v iphone sdk [duplicate] - iphone, objektív-c, xcode, ios4, uitextview

Možné duplicitné:
Zástupný symbol v UITextView

V iPhone App Ako pridať placeHolder Text (držať niektoré predvolené text) v. \ T UItextView?

odpovede:

52 pre odpoveď č. 1

Jednoducho, urobil som to takhle ... pracujem skvelo pre mňa .. Dúfam, že to pomôže niektorým.

#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;
}