【问题标题】:Font With Strike through it带有 Strike 的字体
【发布时间】:2012-05-11 11:47:24
【问题描述】:

我正在做一个处理当天任务的项目,比如记笔记。
所以我分配日常任务去做,当任务完成后,我希望在任务名称中划出一行。
我正在寻找具有此删除线但失败的适当字体系列。
所以请建议我一个 .ttf 字体名称,以便我可以在我的项目中使用该字体来满足我的要求。

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    ******选项 1******

    .

    如果您想在多行模式下删除文本:使用 TTTAttributedLabel

    创建新的 TTTAttributedLabel.h 和 TTTAttributedLabel.m 文件(不是来自 GITHUB,因为我使用单/双删除线功能进行了调整)

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

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

    以及您需要删除线标签的地方 - 使用 TTTAttributedLabel 而不是 UILabel

    设置删除线 =

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

    设置双通 =

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

    添加标签文本应被删除的范围 + 提供可点击的链接(nil,无链接):

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

    附: - 正确重新定位双删除线 - 请编辑 TTTAtributedLabel.m 文件,在第 483、484 和 489、490 行(目前我从中心更改了上行 y-2 和下 y+2。调整它以获得更好的结果。)

    .

    ******选项 2******

    .

    将所有字符串符号转换为特殊的删除线字符。

    您可以从这个主页获得它们:http://adamvarga.com/strike/

    然后您可以 - 例如,将必要的符号翻译放在语言文件中:

    "A" = "A̶"; “B”=“B̶”; "C" = "C̶"; “D”=“D̶”; “E” = “E̶”; “F”=“F̶”; “G” = “G̶”; "H" = "H̶"; ....

    并使用此功能,将普通文本字符串转换为删除字符串:

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

    例如:

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

    ****选项 3****

    我还建议尝试这里提到的 UILabel 子类:Underline text in UIlabel

    希望有帮助!

    【讨论】:

    • 嗨..只有一个问题..你知道是否有可用的双删除线工具。如果是,请提前给我发送链接..thanx。
    • 嗨 kdeo_16 - 我稍微调整了一下 TTTAtributedLabel,现在它支持双三线删除。这是一个快速修复,它的工作原理。 (请参阅更新的答案),但请继续调整自己以获得更好的结果:) 希望有所帮助! :)
    • 嘿,第一个选项对我不起作用。你能帮帮我吗
    • 感谢您的项目 - 真的很容易找到问题:) 这是我的错 - 您还需要提供这行代码: [labelName addLinkToURL:nil withRange:NSMakeRange(0, [labelName.文本长度])];它不仅禁用链接,而且 - 设置要删除的标签范围。另外 - 你应该首先设置标签文本,然后才添加属性。
    • @GuntisTreulands 感谢您的回复,我添加了该行,但它没有像带下划线的那样突出文本
    【解决方案2】:

    如果你使用另一个简单的想法,它的工作也很好,也很容易......

    只需在标签上方添加另一个标签,标签代码是

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

    这里哪个标签要你删除线字体只是把它的框架给这里,当你的任务完成时添加这个标签 希望,这对你有帮助...... :)

    【讨论】:

    • 谢谢。在不使用第三方的情况下,它对我来说工作正常。
    【解决方案3】:

    使用下面的代码来划线:

    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];
    

    【讨论】:

      【解决方案4】:

      用 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
      

      【讨论】:

        【解决方案5】:

        在 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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-05-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-12-13
          • 1970-01-01
          • 1970-01-01
          • 2012-10-22
          相关资源
          最近更新 更多