IOS UITextView 提交建议反馈

</pre></p><pre name="code" class="html">利用UITextView 来提交多行内容的文字。
    _contentTextView = [[UITextView alloc]initWithFrame:CGRectMake(0, 74, kDEVICEWIDTH, 240)];
    _contentTextView.backgroundColor = [UIColor whiteColor];
    _contentTextView.delegate = self;
    _contentTextView.font = TextFont;
    [self.view addSubview:_contentTextView];
    
    _placeHolderLabel = [[UILabel alloc]init];
    _placeHolderLabel.frame = CGRectMake(0, 5, kDEVICEWIDTH, 20);
    _placeHolderLabel.text = @"建议";
    _placeHolderLabel.enabled = NO;
    _placeHolderLabel.backgroundColor = [UIColor clearColor];
    _placeHolderLabel.font = TextFont;
    [_contentTextView addSubview:_placeHolderLabel];

#pragma mark -- UITextFieldDelegate

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    
    if ([_contentTextView isFirstResponder])
    {
        [_contentTextView resignFirstResponder];
    }
}


-(void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0) {
        _placeHolderLabel.text = @"建议";
    }else{
        _placeHolderLabel.text = @"";
    }
}

IOS UITextView 提交建议反馈_第1张图片

你可能感兴趣的:(IOS UITextView 提交建议反馈)