0

In my main view I have a user-defined class drawSquare that is a subclass of UIImageView. In drawSquare.m I have the normal drawRect method shown below:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(context, 2.0);
    CGContextSetStrokeColorWithColor(context,[UIColor redColor].CGColor);
    redSquare = CGRectMake(2,2,30,34);
    CGContextAddRect(context, redSquare);
    CGContextStrokePath(context);
}

In my main view controller I have an object named word1Area of type drawSquare as an IBOutlet. In my viewDidLoad method of my main view controller I have the lines:

[self.view addSubview:word1Area];
[word1Area drawRect:word1Area.frame];

I get an "invalid context" run time error. I have tried other variations of calling the drawRect method but keep getting the same error. Thanks for any help.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Gil
  • 101
  • 6
  • have you seen this answer http://stackoverflow.com/questions/13153223/how-to-crop-the-image-using-uibezierpath/15353848#15353848 – umer sufyan May 31 '13 at 05:23

1 Answers1

0

You cannot call drawRect yourself - you can tell the view setNeedsDisplay.

David H
  • 40,852
  • 12
  • 92
  • 138