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