TTTAttributedLabel UILabel的改进版

程序名称:TTTAttributedLabel

授权协议: MIT

操作系统: iOS

开发语言: Objective-C

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

相关编程语言

Acapela TTS 是一个为 iPhone 和 iPad 开发的 TTS 引...
二维码(QR Code)扫描静态库,扫描效率较高。
RegexKitLite 是一个轻量级的 Objective-C 的正则表...
一款基于ASIHttpReques开源的仿迅雷多线程断点续传功...
实现动态检测网络(wifi)状况,不需要用户手动刷新...
使用iphoneSDK官方NSXMLParserDelegate做的简单xml解...