Etre débutant dans le dessin iOS, je voulais dessiner un petit conteneur d'info-bulle qui se compose d'un rectangle avec une flèche indicatrice. J'ai créé 2 UIBezierPaths et je les ai rejoints avec "appendPath". Je pensais que c'était la bonne façon d'y parvenir, mais après avoir lutté pendant 1 jour, j'ai dû demander de l'aide. est ici la capture d'écran d'où je suis en ce moment:Rejoindre le trait UIBezierPath dans son ensemble
Comme vous pouvez le voir, le problème est simplement que lorsque je tente de caresser le chemin rejoint, il ne se pas caressait dans son ensemble, mais comme pièces séparées. Peut-être que quelqu'un pourrait me diriger dans la bonne direction pour résoudre ce problème?
Voici le code:
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// create indicator path
UIBezierPath *indicator = [[UIBezierPath alloc] init];
// corner radius
CGFloat radius = self.cornerRadius;
// main path
UIBezierPath *path;
// format frame
rect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - self.indicatorSize.height);
// assign path
path = [UIBezierPath bezierPathWithRoundedRect: rect
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(radius, radius)];
// x point
CGFloat x = (rect.size.width - self.indicatorSize.width)/2;
[indicator moveToPoint:CGPointMake(x, rect.size.height)];
[indicator addLineToPoint:CGPointMake(x + self.indicatorSize.width/2, rect.size.height + self.indicatorSize.height)];
[indicator addLineToPoint:CGPointMake(x + self.indicatorSize.width, rect.size.height)];
// close path
[indicator closePath];
// append indicator to main path
[path appendPath:indicator];
[[UIColor redColor] setStroke];
[path setLineWidth:2.0];
[path stroke];
[self.fillColor setFill];
[path fill];
// release indicator
[indicator release];
}
Merci à l'avance
Salut. Merci pour le conseil, mais j'ai essayé et bien qu'il semble fonctionner, il dessine une double bordure sur la bordure inférieure, je n'ai aucune idée pourquoi Vous pouvez le vérifier ici: http://oi51.tinypic.com/2cxevmd.jpg . Et voici le nouveau code que je dessine: http://pastebin.com/imcvhGdQ. Est-ce que je fais quelque chose de mal? – Hidden
Essayez de commencer le dessin sur 0.5,0.5 pour éviter de dessiner sur demi-pixels: Voir ceci pour plus de détails http://www.cocoabuilder.com/archive/cocoa/204399-drawing-1-pixel-perfect-wide-bordered-nsbezierpath .html – iain
J'ai répondu ici avec une image: http://stackoverflow.com/a/15097830/210171 – nielsbot