加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 01:54:18 所属栏目:百科 来源:网络整理
导读:Possible Duplicate: 07000 在iPhone应用程序如何在UItextView中添加placeHolder文本(以保留一些默认文本)? 解决方法 简单,我这样做了..为我工作很好..希望这有助于一个.. #pragma mark -#pragma mark TextView Delegate methods UITextView itsTextView =

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读