Ios UITextView prompt text

Source: Internet
Author: User

Ios UITextView prompt text

Define two uitextviews, one for the input text and the other for displaying the prompt information. If the input text is empty, the prompt information is displayed. Otherwise, the prompt information is not displayed.

// 6.3.1 text content prompt _ contentTextViewTip = [[UITextView alloc] initWithFrame: CGRectMake (12, 5, WIDTH_SCREEN-12-12,105)]; if (_ contentTextViewTip! = Nil) {_ contentTextViewTip. text = POST_CONTENT_TIP; _ contentTextViewTip. font = [UIFont systemFontOfSize: 16.0]; _ contentTextViewTip. userInteractionEnabled = NO; _ contentTextView. delegate = self; _ contentTextViewTip. textColor = [[UIColor alloc] initWithRed: 160/255. 0 green: 160/255. 0 blue: 160/255. 0 alpha: 1.0]; [scrollView addSubview: _ contentTextViewTip];} // 6.3.2 text content textbox _ textViewRect = CGRectMake (12, 5, WIDTH_SCREEN-12*2,105); if (_ contentTextView! = Nil) {_ contentTextView = [[UITextView alloc] initWithFrame: _ textViewRect]; _ contentTextView. backgroundColor = [UIColor clearColor]; _ contentTextView. font = [UIFont systemFontOfSize: 16.0]; // _ contentTextView. textColor = [[UIColor alloc] initWithRed: 160/255. 0 green: 160/255. 0 blue: 160/255. 0 alpha: 1.0]; // _ contentTextView. text = @ "what do you mean ~ "; [_ ContentTextView setScrollEnabled: YES]; _ contentTextView. userInteractionEnabled = YES; _ contentTextView. showsVerticalScrollIndicator = YES; CGSize size = CGSizeMake (WIDTH_SCREEN-12*2, 600366f); [_ contentTextView setContentSize: size]; _ contentTextView. returnKeyType = UIReturnKeyDone; _ contentTextView. keyboardType = UIKeyboardTypeDefault; _ contentTextView. delegate = self; [scrollView addSubview: _ contentTextView];}

# Pragma mark _ contentTextView Delegate/*** event triggered when text changes */-(void) textViewDidChange :( UITextView *) textView {NSLog (@ "textViewDidChange: % @", textView. text); if (textView ==_contenttextview) {if ([textView. text isEqualToString: @ ""]) {_ contentTextViewTip. alpha = 1;} else {_ contentTextViewTip. alpha = 0 ;}}}


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.