与罢工的字体通过它
我正在做一个笔记处理任务的项目。
所以我分配了每天的任务做,当任务完成时,我想要一行通过任务名称罢工。
我正在寻找适当的字体系列,有这个通过线,但失败了。
所以请build议我一个.ttf字体名称,以便我可以在我的项目中使用该字体来满足我的要求。
******选项1******
。
如果您想在多行模式下敲击文本,请使用TTTAttributedLabel
创build新的TTTAttributedLabel.h和TTTAttributedLabel.m文件(不是从GITHUB,因为我调整了单/双删除线function)
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"];
设置doublethrough =
TTTAttributedLabel *labelName = [[TTTAttributedLabel alloc] init]; labelName.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"TTTCustomDoubleStrikeOut"];
添加标签文本的范围,提供可点击链接(无,无链接):
//set link to nil, to NOT-have a link on taping on this label. [labelName addLinkToURL:nil withRange:NSMakeRange(0, [labelName.text length])];
PS – 正确地重新定位双重删除线 – 请编辑TTTAtributedLabel.m文件,在第483,484和489,490行(现在我改变上面的y-2和y + 2从中心调整,以获得更好的结果)。
。
****** OPTION 2 ******
。
将所有string符号转换为特殊的穿透字符。
你可以从这个主页获得它们: http : //adamvarga.com/strike/
那么你可以 – 例如,把必要的符号翻译成语言文件:
“A”=“A”; “B”=“B”; “C”=“C”; “D”=“D”; “E”=“E”; “F”=“F”; “G”=“G̶”; “H”=“H”; ….
并使用这个函数,把正常的文本string变成striked outstring:
- (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"];
****scheme3 ****
我也build议尝试这里提到的这个UILabel子类: 在UIlabel下划线文本
希望有所帮助!
如果你使用另一个简单的想法,它的工作很好,也很容易….
只要在你的标签上添加另外一个标签即可
UILabel *canceledlable = [[UILabel alloc] initWithFrame:yourmainlableframe]; canceledlable.opaque = YES; canceledlable.backgroundColor = [UIColor clearColor]; canceledlable.text = @"------------------------------------------------"; canceledlable.lineBreakMode = UILineBreakModeClip; [self.view addSubview: canceledlable];
这里哪些标签希望你删除字体只是把它的框架到这里,并添加这个标签,当你的任务完成希望,这有助于你…… 🙂
使用下面的代码来通过线条:
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];
尝试添加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
在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