如何在UItextView中添加placeHolder文本?在iphone sdk

Possible Duplicate:
07000

在iPhone应用程序如何在UItextView中添加placeHolder文本(以保留一些默认文本)?

解决方法

简单,我这样做了..为我工作很好..希望这有助于一个..

#pragma mark -
#pragma mark TextView Delegate methods


    UITextView itsTextView = [[UITextView alloc] initWithFrame:CGRectMake(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;
}

相关文章

在有效期内的苹果开发者账号(类型为个人或者公司账号)。还...
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台...
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可...
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Li...