TYAttributedLabel(一) 初步使用
2016-08-12 17:06
253 查看
#import "ViewController.h" #import "TYAttributedLabel.h" #import "TYTextStorage.h" @interface ViewController ()<TYAttributedLabelDelegate> @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; TYAttributedLabel *label = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(0, 100, CGRectGetWidth(self.view.frame), 0)]; label.delegate = self; NSString *text = @"\t总有一天你将破蛹而出,成长得比人们期待的还要美丽。\n"; [label setText:text]; TYTextStorage *textStorage = [[TYTextStorage alloc]init]; textStorage.range = [text rangeOfString:@"总有一天你将破蛹而出"]; textStorage.textColor = [UIColor orangeColor]; textStorage.font = [UIFont systemFontOfSize:16]; [label addTextStorage:textStorage]; TYLinkTextStorage *linkStorage = [[TYLinkTextStorage alloc]init]; linkStorage.range = [text rangeOfString:@"期待"]; [label addTextStorage:linkStorage]; [label sizeToFit]; [self.view addSubview:label]; } - (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageClicked:(id<TYTextStorageProtocol>)textStorage atPoint:(CGPoint)point{ NSRange rang = [textStorage range]; NSString *msg = attributedLabel.text; msg = [msg substringWithRange:rang]; NSLog(@"---->%@",msg); if ([msg isEqualToString:@"期待"]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.baidu.com/"]]; } } @end
相关文章推荐
- iOS开发—使用TYAttributedLabel实现字体大小颜色各异并且带链接的文本
- TTTAttributedLabel 使用方法
- TTTAttributedLabel 使用方法
- TTTAttributedLabel 使用方法
- DTAttributedLabel 使用方法
- TTTAttributedLabel 使用小记
- TTTAttributedLabel的使用
- 【Swift】TTTAttributedLabel使用小记
- TTTAttributedLabel使用介绍(转)
- TYAttributedLabel——简单,强大的iOS属性文本控件
- 富文本(TYAttributedLabel 简单,强大的属性文本控件(无需了解CoreText),支持图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示)
- TTTAttributedLabel第三方使用(一段连续的字符串不同范围用不同字体和颜色)
- 源码推荐(5.14):TYAttributedLabel简单易用的富文本,高仿iOS 系统计算器(基本功能)
- TTTAttributedLabel 使用方法
- TTTAttributedLabel 使用方法 (可点击文字文本)
- TTTAttributedLabel 使用方法
- TTTAttributedLabel 使用方法
- 在tableview的label使用NSMutableAttributedString要注意
- TTTAttributedLabel 使用
- iOS TTTAttributedLabel 使用