2

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.

KDeogharkar
  • 10,939
  • 7
  • 51
  • 95

5 Answers5

5

******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!

Community
  • 1
  • 1
Guntis Treulands
  • 4,764
  • 2
  • 50
  • 72
  • hi..only one question.. Do you know whether there is double strike-through tool available or not. if it is then send me link.. thanx in advance. – KDeogharkar May 12 '12 at 05:56
  • Hi kdeo_16 - I tweaked a little bit TTTAtributedLabel and now it supports double strikeout. It's a quick fix and it works. (see updated answer), but please carry on tweaking yourself for better results :) Hope that helps! :) – Guntis Treulands May 12 '12 at 10:22
  • hey thats not working for me the first option. can u please help me – Dhara Jun 14 '12 at 05:12
  • Thank you for project - really easy to find the problem :) It was my bad - You need also to provide this line of code: [labelName addLinkToURL:nil withRange:NSMakeRange(0, [labelName.text length])]; it not only disables link, but also - sets range for label to be striked out. Also - you should first set label text, and only then add atributes. – Guntis Treulands Jun 14 '12 at 09:21
  • @GuntisTreulands thanks for ur reply i added that line but its not striking the text its like underlined one – Dhara Jun 14 '12 at 09:29
  • http://www.sendspace.com/file/n9drhh here, i zipped your project -works on my end. :) – Guntis Treulands Jun 14 '12 at 10:08
2

Use below code to stripe through the line:

NSString *string = Yourlabel.text;
CGSize stringSize = [string sizeWithFont:Yourlabel.font];
CGRect buttonFrame = Yourlabel.frame;
CGRect labelFrame = CGRectMake(buttonFrame.origin.x , 
buttonFrame.origin.y + stringSize.height/2, 
                                           stringSize.width, 2);
UILabel *lineLabel = [[UILabel alloc] initWithFrame:labelFrame];
lineLabel.backgroundColor = [UIColor blackColor];
[CellView addSubview:lineLabel];
Rui Peres
  • 25,741
  • 9
  • 87
  • 137
Narayana Rao Routhu
  • 6,303
  • 27
  • 42
2

If you use another simple idea its work fine and also very easy....

just add another lable above your lable and lable code is

UILabel *canceledlable = [[UILabel alloc] initWithFrame:yourmainlableframe];
canceledlable.opaque = YES;
canceledlable.backgroundColor = [UIColor clearColor];
canceledlable.text = @"------------------------------------------------";
canceledlable.lineBreakMode = UILineBreakModeClip;
[self.view addSubview: canceledlable];

here which lable want you strikethrough font just give its frame to here and add this lable when your task is done Hope,this help you...... :)

Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
1

Try this additions with TTTAttributedLabel.

@implementation TTTAttributedLabel (Additions)

- (void)setStrikeThroughOn:(BOOL)isStrikeThrough {
    NSString* text = self.text;
    [self setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^        NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) {
    NSRange strikeRange = [[mutableAttributedString string] rangeOfString:text options:NSCaseInsensitiveSearch];
    [mutableAttributedString addAttribute:kTTTStrikeOutAttributeName value:[NSNumber numberWithBool:isStrikeThrough] range:strikeRange];
    return mutableAttributedString;
}];

// must trigger redraw
[self setNeedsDisplay];
}

@end
shiami
  • 7,174
  • 16
  • 53
  • 68
0

In Swift,

let label = UITextView(frame: CGRectMake(0, 0, 300, 100))
let strikeThroughAttributes = [NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue]
let labelString = NSAttributedString(string: "Hello, playground", attributes: strikeThroughAttributes)
label.attributedText = labelString
wye
  • 316
  • 4
  • 7