IOS control UITextView achieves placeholder effect and solves UITableView keyboard occlusion

Source: Internet
Author: User

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

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.