ios - UItextView设置提示性文字
伊谢尔伦
伊谢尔伦 2017-04-17 17:33:03
[iOS讨论组]

iOS 的textView有没有自带的设置提示文字的方法,我试过在上面加一个UILabel可以实现,但是觉得有点麻烦,求大神指教一下!

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(2)
迷茫

自己写个逻辑


// tips是提示文本

- (void)addTextView {
    UITextView *textView = [UITextView new];
    textView.text = tips;
    textView.textColor = [UIColor grayColor];
    _inputContent = @"";
    ………………省略
}

- (void)textViewDidBeginEditing:(UITextView *)textView {
    if ([_inputContent isEqualToString:@""]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    } else {
        textView.textColor = [UIColor blackColor];
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView {
    if (textView.text && [textView.text length] > 0) {
        _inputContent = textView.text;
        textView.textColor = [UIColor blackColor];
    } else {
        _inputContent = @"";
        textView.text = tips;
        textView.textColor = [UIColor grayColor];
    }
    
}

textView里显示的是表象,_inputContent相当于你的数据源

天蓬老师

注意placeholder是自定义的添加到texView即可

- (void)paste:(id)sender
{
    
    UIPasteboard *board = [UIPasteboard generalPasteboard];
    self.textView.text = board.string;
    [self resignFirstResponder];
}

-(void)keyboardHideClick:(UITapGestureRecognizer*)tap{
    
    [self.textView resignFirstResponder];
    
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

{    if (![text isEqualToString:@""])
    
{
    
    _placeholderLabel.hidden = YES;
    
}
    
    if ([text isEqualToString:@""] && range.location == 0 && range.length == 1)
        
    {
        
        _placeholderLabel.hidden = NO;
        
    }
    
    return YES;
    
}
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号