2012-12-04 25 views

risposta

9
- (void)drawRect:(CGRect)rect { 
    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGPathRef path = CGPathCreateWithRect(rect, NULL); 
    [[UIColor redColor] setFill]; 
    [[UIColor greenColor] setStroke]; 
    CGContextAddPath(context, path); 
    CGContextDrawPath(context, kCGPathFillStroke); 
    CGPathRelease(path); 
} 

Anche se, non posso dire che è meno prolissa di ictus & riempimento in chiamate separate ...

+0

Hmm ... molto vero, mi limiterò a andare con chiamate separate Credo. Grazie. – chinabuffet

-1

CGContextDrawPath esegue questa operazione se si impostano prima il colore di riempimento e il tratto.

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetStrokeColor(context, a); 
CGContextSetFillColor(context, b); 
CGContextDrawPath(context, rect) 
+8

Hmm ... la firma del 'CGContextDrawPath' vedo nel file di intestazione è:' CGContextDrawPath (CGContextRef c, modalità CGPathDrawingMode) ' – chinabuffet

6

Se stai solo cercando di risparmiare spazio linea, è possibile definire la vostra metodo proprio per effettuare due chiamate e posizionarlo in una classe di utilità.

void strokeAndFill(CGContextRef c, CGRect rect) 
{ 
    CGContextFillRect(c, rect); 
    CGContextStrokeRect(c, rect); 
} 
Problemi correlati