0

I want to improve a super cool text view with placeholder and add to it super cool frame like textField has. To do it you simply need to add this code to your awakeFromNib method:

- (void)awakeFromNib
{
    [super awakeFromNib];
    if (self.editable) {
        CALayer *selfLayer = self.layer;
        UIImage *stretchableImage = [UIImage imageNamed:@"TextView"];
        selfLayer.contents = (id)stretchableImage.CGImage;
        selfLayer.contentsScale = [UIScreen mainScreen].scale; // Needed for the retina display, otherwise our image will not be scaled properly.
        selfLayer.contentsCenter = CGRectMake(0.5, 0.5, 1.0/stretchableImage.size.width,1.0/stretchableImage.size.height);

        self.backgroundColor = [UIColor clearColor];
    }
}

The problem is if you add this if() to the above mentioned placeholderTextView's awakeFromNib the drawRect method of the placeholderTextView does not getting called! WHY ? Is it because of accessing layer property of this view? Please guide me through this graphics stuff..!

Community
  • 1
  • 1
Stas
  • 9,925
  • 9
  • 42
  • 77
  • While not an answer to your exact question, have you tried adding `[self setNeedsDisplay]` at the end of awakeFromNib? That will force a `drawRect` call. – MikeS Aug 02 '13 at 20:04
  • hmm `setNeedsDisplay` really forced the `drawRect` to be called but...nothing happened ) oh , one should really have good understanding of how ios graphics works before using some advanced drawing.. – Stas Aug 05 '13 at 15:21

0 Answers0