tags:

views:

101

answers:

2
-(void)drawRect:(CGRect)rect
{   

CGContextRef  context = UIGraphicsGetCurrentContext();
CGContextSelectFont(context, "Arial", 24, kCGEncodingFontSpecific);
CGContextSetTextPosition(context,80,80);
CGContextShowText(context, "hello", 6);
//not even this works
CGContextShowTextAtPoint(context, 1,1, "hello", 6);
}

I want to kn ow how to call above method, i have paste above code in the implemntation file simply, but dont know why its not called when i execute the project, can some one

A: 

setNeedsDisplay should do that for you, here is a link link text

The methods is also called when the view first displays...

Daniel
@implementation quartzViewController-(void)drawRect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSelectFont(context, "Arial", 24, kCGEncodingFontSpecific); CGContextSetTextPosition(context,80,80); CGContextShowText(context, "hello", 6); //not even this works CGContextShowTextAtPoint(context, 1,1, "hello", 6);}- (void)viewDidLoad { [self.view setNeedsDisplay]; [super viewDidLoad];}this is what I have done, but I am not actually getting why its happening, why its not called, ever if i am using setNeedsDisplay
still its not working
you dont call it in view did load, call it else where, drawrect is called automatically when the view loads...are u sure u are adding your view correctly?
Daniel
A: 

Finally I got the anser, just take a new class and inherit the class with UIView instead of NSobject,

This class will give us UIView object and it will also contain the drawRect method inbuilt.

so this is How i done. it :)