J'essaie de rendre du texte à une forme qui n'est pas un rectangle. Le code suivant fonctionne lorsque j'ajoute un chemin rectangulaire mais pas quand j'ajoute un chemin elliptique. En fin de compte, je voudrais dessiner à n'importe quel chemin (forme de L, etc.), a-t-on eu de la chance avec ceci?Texte principal: Rendu à une forme impaire
-(void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGMutablePathRef path = CGPathCreateMutable();
float w = 200.0;
float h = 300.0;
CGRect bounds = CGRectMake(10.0, 10.0, w, h);
// I draw using only one of the following lines
CGPathAddRect(path, NULL, bounds); // THIS LINE WILL WORK
//CGPathAddEllipseInRect(path, NULL, bounds); // THIS LINE WILL CRASH IT
// Initialize an attributed string.
CFStringRef string = CFSTR("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.");
CFMutableAttributedStringRef attrString = CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
CFAttributedStringReplaceString (attrString, CFRangeMake(0, 0), string);
// Create the framesetter with the attributed string.
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(attrString);
CFRelease(attrString);
// Create the frame and draw it into the graphics context
CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
// Flip the text
CGAffineTransform flip = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0, self.frame.size.height);
CGContextConcatCTM(context, flip);
CTFrameDraw(frame, context);
CFRelease(framesetter);
CFRelease(frame);
}
Toute aide ou idée serait grandement appréciée. Je suis perplexe.
Intéressant. Avez-vous trouvé une solution? Vous pourriez vouloir classer un bogue alors ... –
Aucune solution pour le moment. J'ai déposé le bogue # 8523733. CTFramesetterCreateFrame renvoie null pour tout chemin non rectangulaire (le blocage se produit lorsque je relâche le cadre). Selon les docs, cela devrait aller. Je mettrai à jour ce post si je peux obtenir une résolution. – earthbound