IOS control UITextView achieves placeholder effect and solves UITableView keyboard occlusion
At ordinary times, there are always multiple lines of text in development, and there must be a placeholder prompt. You can organize some code in the project for your reference and discussion. I hope you can provide more suggestions for better implementation methods.
Ideas:Placeholder effect is achieved by changing the text color of UITextView. The setContentOffset method of UITableView solves the problem of keyboard occlusion.
1. Create UITextView
TextView = [[UITextViewalloc] init];
TextView. font = [UIFontsystemFontOfSize: 14];
TextView. frame = CGRectMake (10, 0, DEVICE_WIDTH-20, 56 );
TextView. autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
TextView. backgroundColor = [UIColorclearColor];
TextView. textColor = [UIColorcolorWithHexString: @ #999999];
TextView. delegate = self;
TextView. text = @ Please input here;
[Self. view addSubview: textView];
2. UITextView delegate-
# Pragma mark ----- UITextView delegate -----
// Start editing
-(Void) textViewDidBeginEditing :( UITextView *) textView
{
[TableviewsetContentOffset: CGPointMake (0,100) animated: YES];
If ([textView. textisEqualToString: @ Please input here]) {
TextView. textColor = [UIColorcolorWithHexString: @ #77FF00];
TextView. text = @;
}
}
// Complete editing
-(Void) textViewDidEndEditing :( UITextView *) textView
{
If (textView. text. length = 0 | [textView. textis#tostring: @]) {
TextView. textColor = [UIColorcolorWithHexString: @ #999999];
TextView. text = @ Please input here;
}
Else
{
DetailAddress. text = textView. text;
}
[TableviewsetContentOffset: CGPointMake (0, 0) animated: YES];
}