Question

Je dois tirer surlignés-multiligne avec tous les types d'alignement du texte. J'ai cherché sur les forums et a obtenu des résultats comme:

http: //davidjhinson.wordpress. com / 2009/11/26 / / underline texte-on-the-iphone

http://forums.macrumors.com/showthread.php?t=561572

Mais tout le texte de tirage au sort pour seule ligne. alors que j'ai texte de plusieurs lignes. La situation même empiré lorsque l'alignement du texte est centré. J'ai cherché et trouvé que, dans l'iphone-sdk-3.2 il y a un certain texte de base des attributs pour souligner un texte, mais aucune idée de comment l'utiliser. D'ailleurs si je les utilise mon problème ne serait pas résolu complètement.

Comme je dois dessiner du texte aussi barrés.

Toute personne ayant idée de cette aide s'il vous plaît.

Était-ce utile?

La solution

Qu'en est-ce. Cela fonctionne bien pour moi ce que vous pensez tous, si cela a besoin d'optimisation?

CGContextSetFillColorWithColor(c, [[UIColor blackColor] CGColor]);          //THE TEXT COLOR OF THE STRING TO BE DRAWN.

            UIFont *fontName = [UIFont fontWithStyle:@"Arial-BoldMT" andFontSize:13];

            if(FontOverLayUnderLine || FontOverLayStrikeThrough){

                NSArray *stringsArray = [textString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
                CGContextSetStrokeColorWithColor(c, [appDel.textDisplayStyle.fillColor CGColor]);
                CGContextSetLineWidth(c, 1.0);
                CGSize stringSize;
                NSString *stringToDraw;
                for (int i = 0 ; i < [stringsArray count]; i++) {

                    stringToDraw = [stringsArray objectAtIndex:i];

                    if(![[stringToDraw stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:@""]){

                        stringSize = [stringToDraw sizeWithFont:fontName forWidth:rect.size.width lineBreakMode:UILineBreakModeCharacterWrap];

                        float x = rect.origin.x + (rect.size.width-stringSize.width)/2 + 7;
                        float y = 4 + stringSize.height*i;

                        [stringToDraw drawAtPoint:CGPointMake(x, y) forWidth:stringSize.width withFont:fontName lineBreakMode:UILineBreakModeCharacterWrap];

                        if(FontOverLayUnderLine)
                            y += (1.05) * stringSize.height*i +1;
                        else
                            y += (stringSize.height/2)+1;

                        CGContextMoveToPoint(c, x, y);
                        CGContextAddLineToPoint(c, x+stringSize.width, y);
                        CGContextStrokePath(c);
                    }
                }

            }

Espérons que cela fonctionne bien pour tous.

Merci,

Madhup

Autres conseils

Utilisation de base Texte.

  

J'ai cherché et trouvé que, dans l'iphone-sdk-3.2 il y a un certain texte de base des attributs pour souligner un texte, mais aucune idée de comment l'utiliser.

C'est ce que la documentation est pour.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top