画下划线/删除线文字(MULTILINE STRING)?

Mad*_*dav 5 iphone core-graphics ipad iphone-sdk-3.2 core-text

我必须使用所有类型的文本对齐绘制带下划线的多行文本.我在论坛上搜索过并获得了一些结果:

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

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

但是所有人都只为单行绘制文字.虽然我有多行文字.当文本对齐居中时,情况甚至变得更糟.我搜索并发现在iphone-sdk-3.2中有一些核心文本属性用于加下划线,但不知道如何使用它.此外,如果我使用这些,我的问题将无法完全解决.

因为我还要画出删除线文字.

有任何想法的人请帮忙.

Mad*_*dav 2

那这个呢。大家认为这对我来说很有用,是否需要一些优化?

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

            }
Run Code Online (Sandbox Code Playgroud)

希望这对所有人都有好处。

谢谢,

马杜普