Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
631 views
in Technique[技术] by (71.8m points)

iphone - Font With Strike through it

I am doing one project of handling task of the day like taking notes.
So I assign daily task to do and when task is done I want one line strike through the task name.
I am searching for the appropriate font-family that has this strike-through line but failed.
so please suggest me a .ttf font name for that so I can use that font in my project to fulfill my requirement.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

******OPTION 1******

.

If You want to strike through text in multiline mode: use TTTAttributedLabel

create new TTTAttributedLabel.h and TTTAttributedLabel.m files (not from GITHUB, because I tweaked with single/double strikethrough feature)

http://www.2shared.com/file/Z_qZpWVd/TTTAttributedLabel.html

http://www.2shared.com/file/xXjmC-1M/TTTAttributedLabel.html

and where you need a strikethrough label - use TTTAttributedLabel instead of UILabel.

To set strikethrough =

TTTAttributedLabel *labelName = [[TTTAttributedLabel alloc] init];

labelName.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] 
                forKey:@"TTTCustomStrikeOut"];   

To set doublethrough =

TTTAttributedLabel *labelName = [[TTTAttributedLabel alloc] init];

labelName.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] 
                forKey:@"TTTCustomDoubleStrikeOut"];

Add range where label text should be striked out + provide clickable link (nil , for no link):

//set link to nil, to NOT-have a link on taping on this label.
[labelName addLinkToURL:nil withRange:NSMakeRange(0, [labelName.text length])];

P.S. - to properly reposition double strikeout lines - please edit TTTAtributedLabel.m file, at lines 483, 484 and 489, 490 (currently I changed upper line y-2 and lower y+2 from center. tweak that for better results.)

.

******OPTION 2******

.

Convert all string symbols to special strike-through characters.

You can get them from this homepage: http://adamvarga.com/strike/

Then You can - for example, put necessary symbol translations in language file:

"A" = "A?"; "B" = "B?"; "C" = "C?"; "D" = "D?"; "E" = "E?"; "F" = "F?"; "G" = "G?"; "H" = "H?"; ....

and use this function, to turn normal Text string to striked out string:

- (NSString *)returnStrikedOutTextFromString:(NSString *)mString
{
    NSString * mNewString = @"";

    for(int i = 0; i<[mString length]; i++)
    {
        mNewString = [NSString stringWithFormat:@"%@%@",mNewString, 
        NSLocalizedString([[mString substringToIndex:i+1] substringFromIndex:i],nil)];
    }

    return mNewString;
}

for example:

textLabel.text = [self returnStrikedOutTextFromString:@"string text"];

****OPTION 3****

I would also suggest trying this UILabel subclass mentioned here: Underline text in UIlabel

Hope that helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...