Draw underlined / strikethrough text (MULTILINE STRING)?

I need to draw underlined-multi-line text with all types of text alignment. I searched the forums and got some results, for example:

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

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

But everyone draws text for only one line. while I have multi-line text. The situation even worsens when the alignment of the text is concentrated. I searched and found that iphone-sdk-3.2 has some basic text attributes for underlining text, but I don't know how to use it. In addition, if I use them, my problem will not be completely solved.

How should I draw strikethrough text.

Anyone have an idea about this, please help.

+5
source share
2 answers

How about this one. This works well for me, what do you all think if it requires some optimization?

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);
                    }
                }

            }

Hope this works well for everyone.

Thank,

Madhup

+2
source

Use body text.

I searched and found that iphone-sdk-3.2 has some basic text attributes for underlining text, but I don't know how to use it.

This is for documentation .

+1
source

All Articles