J'ai ces 2 méthodes dans la classe View. La méthode drawRect est toujours appelée lorsque la vue est initialisée. Mais je n'arrive pas à utiliser la méthode drawLine pour fonctionner. Il ne fait rien quand on l'appelle. Suis-je censé faire face à cgimagecontext ou quelque chose comme ça? aidez s'il vous plaît !!Comment créer une méthode de dessin dans une classe View en utilisant CGContextRef?
- (void)drawRect:(CGRect)rect {
// Drawing code
// Drawing code
CGContextRef contextRef = UIGraphicsGetCurrentContext();
//CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1);
CGContextSetRGBStrokeColor(contextRef, 0, 0, 0, 1);
CGContextSetLineWidth(contextRef, 5.0);
CGContextBeginPath(contextRef);
CGContextMoveToPoint(contextRef, 0, 0);
CGContextAddLineToPoint(contextRef, 320, 480);
CGContextStrokePath(contextRef);
}
-(void)drawLine:(CGPoint)from to:(CGPoint) to {
// Drawing code
CGContextRef contextRef = UIGraphicsGetCurrentContext();
//CGContextSetRGBFillColor(contextRef, 0, 0, 255, 1);
CGContextSetRGBStrokeColor(contextRef, 0, 128, 0, 1);
CGContextSetLineWidth(contextRef, 5.0);
CGContextBeginPath(contextRef);
CGContextMoveToPoint(contextRef, 0, 0);
CGContextAddLineToPoint(contextRef, 320, 50);
CGContextStrokePath(contextRef);
}
oh je l'ai eu Ben, merci beaucoup !!! :) – RoundOutTooSoon