Search code examples
objective-cxcodedrawrectcgrect

how to call drawrect method from another class when it is made in appdelegate class


I have made a method in appdelegate class which is-

@implementation UINavigationBar (category)
- (void)drawRect:(CGRect)rect{
       UIImage *img = [UIImage newImageFromResource:@"Img.png"];
       [img drawInRect:rect];
       [img release];
}
@end

I want to set the size(x,y,width,height) of the image(Img.png) programitcally in some other class..so how to call/use (- (void)drawRect:(CGRect)rect) method in some other class?


Solution

  • do like this

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDelegate drawRect:CGRectMake(x,y,width,height)];