2010-11-07 6 views
0

Je veux dessiner un rectangle avec le coin en haut à gauche arrondi avec 3 sous-espaces. Quelque chose comme ceci:Dessin simple avec Quartz - Core Graphics

_______ 
|_|_____| 
|  | 
|_______| 

Mais pour une raison quelconque, je ne peux pas tirer les deux lignes intérieures dessinées.

- (void) drawRect:(CGRect)rect{ 
CGContextRef context = UIGraphicsGetCurrentContext(); 
float cornerRadius = 25.0; 
float w = self.bounds.size.width; 
float h = self.bounds.size.height; 
CGContextMoveToPoint(context, cornerRadius, 0); 
CGContextAddQuadCurveToPoint(context, 0, 0, 0, cornerRadius); 
CGContextAddLineToPoint(context, 0, h); 
CGContextAddLineToPoint(context, w, h); 
CGContextAddLineToPoint(context, w, 0); 
CGContextAddLineToPoint(context, cornerRadius, 0); 

//drawing settings 
CGContextSetLineWidth(context, 0.5); 
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 
CGContextSetFillColorWithColor(context, [UIColor white].CGColor); 

//draw rectangle 
CGContextDrawPath(context, kCGPathFillStroke); 

//draw title/label partition 
CGContextMoveToPoint(context, TITLE_HEIGHT, 0); 
CGContextAddLineToPoint(context, TITLE_HEIGHT, TITLE_HEIGHT); 
CGContextStrokePath(context); 

//draw title/content partition 
CGContextMoveToPoint(context, 0, TITLE_HEIGHT); 
CGContextAddLineToPoint(context, self.bounds.size.width, TITLE_HEIGHT); 
CGContextStrokePath(context); 
} 

Je me demande ce que je suis ici ... confondant; (

Merci à l'avance

+1

Qu'est-ce que vous avez défini TITLE_HEIGHT comme? Si c'était 0, alors cela expliquerait le comportement observé ... – westsider

+1

Vous pouvez couper le premier 'CGContextStrokePath' Chaque chaque' moveto' démarre un sous-chemin, le chemin courant (ou un CGPath objet) peut contenir plusieurs sous-pattes hs. Le second 'CGContextStrokePath', une fois seul, attirera les deux. –

+1

Votre code fonctionne pour moi une fois que je définis TITLE_HEIGHT et corriger typo "[UIColor blanc]" == >> "[UIColor whiteColor]" – westsider

Répondre

0

Essayez de commenter la ligne CGContextSetFillColorWithColor pendant un certain temps - peut-être le rectangle chevauche ces lignes

?
+0

Je viens d'essayer ça, ce n'était pas le cas; ( – nacho4d

+0

Le dessin postérieur chevauche le dessin précédent, et non l'inverse. –

Questions connexes