画下划线/删除线文字(MULTILINE STRING)? [英] Draw underlined / strikethrough text ( MULTILINE STRING )?

查看:143
本文介绍了画下划线/删除线文字(MULTILINE STRING)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have to draw underlined-multiline text with all types of text alignment. I have searched on forums and got some results like:

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

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

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

But all draw text for single line only. while i have multi-line text. The situation even become worse when the text alignment is centered. I searched and found that in iphone-sdk-3.2 there are some core-text attributes for underlining a text but no idea how to use that. Besides if I use these my problem would not be solved fully.

因为我还必须绘制删除线文本。

As I have to draw strikethrough text also.

有任何想法的人请帮忙。

Anybody having idea about this please help.

推荐答案

这个怎么样?如果这需要一些优化,这对你们有什么好处?

What about this. This works good for me what you all think, if this needs some 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);
                    }
                }

            }

希望这个适用于所有人。

Hope this works good for all.

谢谢,

Madhup

这篇关于画下划线/删除线文字(MULTILINE STRING)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆