Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>this is how I did it:</p> <p>UITextView2.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface UITextView2 : UITextView &lt;UITextViewDelegate&gt; { NSString *placeholder; UIColor *placeholderColor; } @property(nonatomic, retain) NSString *placeholder; @property(nonatomic, retain) UIColor *placeholderColor; -(void)textChanged:(NSNotification*)notif; @end </code></pre> <p>UITextView2.m</p> <pre><code>@implementation UITextView2 @synthesize placeholder, placeholderColor; - (id)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self setPlaceholder:@""]; [self setPlaceholderColor:[UIColor lightGrayColor]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil]; } return self; } -(void)textChanged:(NSNotification*)notif { if ([[self placeholder] length]==0) return; if ([[self text] length]==0) { [[self viewWithTag:999] setAlpha:1]; } else { [[self viewWithTag:999] setAlpha:0]; } } - (void)drawRect:(CGRect)rect { if ([[self placeholder] length]&gt;0) { UILabel *l = [[UILabel alloc] initWithFrame:CGRectMake(8, 8, 0, 0)]; [l setFont:self.font]; [l setTextColor:self.placeholderColor]; [l setText:self.placeholder]; [l setAlpha:0]; [l setTag:999]; [self addSubview:l]; [l sizeToFit]; [self sendSubviewToBack:l]; [l release]; } if ([[self text] length]==0 &amp;&amp; [[self placeholder] length]&gt;0) { [[self viewWithTag:999] setAlpha:1]; } [super drawRect:rect]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload