TTTAttributedLabel 介绍
TTTAttributedLabel 是 UILable 的改进,支持 NSAttributedStrings
示例代码:
TTTAttributedLabel *label = [[[TTTAttributedLabel alloc] initWithFrame:CGRectZero] autorelease]; label.font = [UIFont systemFontOfSize:14]; label.textColor = [UIColor darkGrayColor]; label.lineBreakMode = UILineBreakModeWordWrap; label.numberOfLines = 0; NSString *text = @"Lorem ipsum dolar sit amet"; [label setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSAttributedString *(NSMutableAttributedString *mutableAttributedString) { NSRange boldRange = [[mutableAttributedString string] rangeOfString:@"ipsum dolar" options:NSCaseInsensitiveSearch]; NSRange strikeRange = [[mutableAttributedString string] rangeOfString:@"sit amet" options:NSCaseInsensitiveSearch]; // Core Text APIs use C functions without a direct bridge to UIFont. See Apple's "Core Text Programming Guide" to learn how to configure string attributes. UIFont *boldSystemFont = [UIFont boldSystemFontOfSize:14]; CTFontRef font = CTFontCreateWithName((CFStringRef)boldSystemFont.fontName, boldSystemFont.pointSize, NULL); if (font) { [mutableAttributedString addAttribute:(NSString *)kCTFontAttributeName value:(id)font range:boldRange]; [mutableAttributedString addAttribute:@"TTTCustomStrikeOut" value:[NSNumber numberWithBool:YES] range:strikeRange]; CFRelease(font); } return mutableAttributedString; }];
TTTAttributedLabel 官网
https://github.com/mattt/TTTAttributedLabel
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。