{"id":15030182,"url":"https://github.com/12207480/tyattributedlabel","last_synced_at":"2025-05-14T20:04:29.466Z","repository":{"id":31650955,"uuid":"35216269","full_name":"12207480/TYAttributedLabel","owner":"12207480","description":"TYAttributedLabel 简单，强大的属性文本控件(无需了解CoreText)，支持图文混排显示，支持添加链接，image和UIView控件，支持自定义排版显示","archived":false,"fork":false,"pushed_at":"2023-03-16T12:46:19.000Z","size":5188,"stargazers_count":2892,"open_issues_count":79,"forks_count":573,"subscribers_count":77,"default_branch":"master","last_synced_at":"2025-04-09T19:42:34.800Z","etag":null,"topics":["attributedlabel","coretext","ios","label","objective-c","tyattributedlabel"],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/12207480.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2015-05-07T11:29:03.000Z","updated_at":"2025-03-28T09:29:40.000Z","dependencies_parsed_at":"2022-08-07T16:30:41.437Z","dependency_job_id":"4b298874-dc29-4647-bf76-1afa93e430cb","html_url":"https://github.com/12207480/TYAttributedLabel","commit_stats":{"total_commits":258,"total_committers":9,"mean_commits":"28.666666666666668","dds":0.1937984496124031,"last_synced_commit":"4dc17587acc492fb4cc7ec373d6f0360f0bffef3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/12207480%2FTYAttributedLabel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/12207480%2FTYAttributedLabel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/12207480%2FTYAttributedLabel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/12207480%2FTYAttributedLabel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/12207480","download_url":"https://codeload.github.com/12207480/TYAttributedLabel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724639,"owners_count":21151561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attributedlabel","coretext","ios","label","objective-c","tyattributedlabel"],"created_at":"2024-09-24T20:12:41.066Z","updated_at":"2025-04-13T14:05:55.273Z","avatar_url":"https://github.com/12207480.png","language":"Objective-C","readme":"# TYAttributedLabel v2.6\nTYAttributedLabel 简单，强大的属性文本的控件(无需了解CoreText)，支持图文混排显示，支持添加链接，image和UIView控件，支持自定义排版显示\u003cbr\u003e\n\n**新的异步渲染[TYText](https://github.com/12207480/TYText)**：text asynchronous rendering by TextKit\n\n**更新:**\n\u003cbr\u003e详细的使用请看[LovePlayNews](https://github.com/12207480/LovePlayNews)项目\n\u003cbr\u003e使用autolayout 如果需要自动推断高度，必须设置preferredMaxLayoutWidth\n\u003cbr\u003e添加到CocoaPods\n\u003cbr\u003e微博demo（建议真机调试） 下载地址：链接: http://pan.baidu.com/s/1sjnBWRj 密码: t7qn\n\u003cbr\u003ev2.6 新增宽度自适应isWidthToFit，空心字设置strokeWidth，段落间距paragraphSpacing\n\u003cbr\u003ev2.5 把label的一些操作移动textContainer,label只负责draw了。\n\u003cbr\u003ev2.4 修复imge放大bug，新增imageAlignment 和 autolayout支持，以及相应的demo，感谢xinzhengzhang，nonstriater\n\u003cbr\u003ev2.3 新增 做题demo，代码优化\n\u003cbr\u003ev2.2 新增 TYImagecache类,新增 image URL 下载缓存，功能优化，改进\n\u003cbr\u003ev2.1 添加 tableViewCell demo\n\u003cbr\u003ev2.0 重构优化代码，性能提升，稳定（已在项目中使用）, 分离出TYTextContainer ，可以提前生成，也可以生成attributedString，显著提升cell滑动场景流畅度，可以和微博一样流畅\n\u003cbr\u003ev1.2  添加设置行数，修复bug，增强稳定性\n\u003cbr\u003ev1.1  添加链接高亮效果，链接便利方法，长按手势代理，优化代码\n\n## CocoaPods\n```\npod 'TYAttributedLabel', '~\u003e 2.6.2'\n```\n\n## ScreenShot\n\n![image][image-1]\n\n新-做题demo\n\n![image][image-3]\n\nweibo demo 使用TYAttributedLabel 截图\n\n![image][image-2]\n## Requirements\n* Xcode 5 or higher\n* Apple LLVM compiler\n* iOS 6.0 or higher\n* ARC\n\n## Features\n* 支持属性文本，图文混排显示，支持行间距 行间距 段落间距，设置行数，自适应高度，宽度\n* 支持添加自定义文本属性\n* 支持添加属性文本，自定义链接，新增高亮效果显示（文字和背景）\n* 支持添加UIImage和UIView控件\n\n## Demo\n运行demo可以查看效果，而且在demo中，针对各种文本和图文的实现都有详细的用例，每个头文件中都有详细的用法注释，这里简单的介绍下用法\n \n## Usage\n### API Quickstart\n\n* **Category And Protocol**\n\n|Class | Function|\n|--------|---------|\n|NSMutableAttributedString (TY) |category提供便利color,font CharacterSpacing,UnderlineStyle,ParagraphStyle的属性添加，无需了解复杂的CoreText|\n|TYTextStorageProtocol|自定义文本属性 遵守最基本的协议 即可 addTextStorage 添加进去|\n|TYAppendTextStorageProtocol|自定义文本属性协议 遵守即可appendTextStorage 添加进去|\n|TYLinkStorageProtocol|自定义文本链接属性 继承TYAppendTextStorageProtocol|\n|TYDrawStorageProtocol|自定义显示内容协议 如 UIImage UIView|\n\n下层协议继承上层的协议，如果觉得复杂，其实我已经实现了常用的自定义属性，拿来就可以用，或者继承，添加你想要的\n\n* **Label And Storage**\n\n|Class |Function |\n|--------|---------|\n|TYAttributedLabel|简单易用的属性文本,富文本的显示控件,\u003cbr\u003eaddTextStorage在已经设置文本的基础上添加属性，image或者view,\u003cbr\u003eappendTextStorage(无需事先设置文本)直接添加属性，image或者view到最后|\n|TYTextContainer|文本容器，可以提前生成，也可以生成attributedString，显著提升cell滚动流畅度|\n|TYTextStorage|自定义文本属性,支持textColor,font,underLineStyle|\n|TYLinkTextStorage|自定义链接属性，继承TYTextStorage，支持点击代理|\n|TYDrawStorage|自定义显示内容属性，如UIImage，UIView，支持点击代理|\n|TYImageStorage|自定义图片显示，继承TYDrawStorage|\n|TYViewStorage|自定义UIView控件，继承TYDrawStorage|\n|TYImageCache|image缓存类，支持URL请求|\n\n如果需要更加详细的内容，请看各个头文件，有详细的注释\n\n### Delegate\n\n```objc\n\n// 点击代理\n- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageClicked:(id\u003cTYTextStorageProtocol\u003e)textStorage atPoint:(CGPoint)point;\n\n// 长按代理 有多个状态 begin, changes, end 都会调用,所以需要判断状态\n- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageLongPressed:(id\u003cTYTextStorageProtocol\u003e)textStorage onState:(UIGestureRecognizerState)state atPoint:(CGPoint)point;\n\n```\n\n### Examples\n\n* **appendStorage demo**\n\t \n```objc\n\nTYAttributedLabel *label = [[TYAttributedLabel alloc]init];\n[self.view addSubview:label];\n\n// 文字间隙\nlabel.characterSpacing = 2;\n// 文本行间隙\nlabel.linesSpacing = 6;\n\nNSString *text = @\"\\t总有一天你将破蛹而出，成长得比人们期待的还要美丽。\\n\";\n[label appendText:text];\n\nNSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];\n[attributedString addAttributeTextColor:[UIColor blueColor]];\n[attributedString addAttributeFont:[UIFont systemFontOfSize:15]];\n[label appendTextAttributedString:attributedString];\n\n[label appendImageWithName:@\"CYLoLi\" size:CGSizeMake(CGRectGetWidth(label.frame), 180)];\n\nUIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"CYLoLi\"]];\nimageView.frame = CGRectMake(0, 0, CGRectGetWidth(label.frame), 180);\n[label appendView:imageView];\n\n[label setFrameWithOrign:CGPointMake(0,0） Width:CGRectGetWidth(self.view.frame)];\n\n```\n* **addStorage demo**\n\n```objc\n\nTYAttributedLabel *label = [[TYAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0)];\n[self.view addSubview:label];\n\nNSString *text = @\"\\t总有一天你将破蛹而出，成长得比人们期待的还要美丽。\\n\";\n[label setText:text];\n\n// 文字间隙\nlabel.characterSpacing = 2;\n// 文本行间隙\nlabel.linesSpacing = 6;\n\ntextStorage = [[TYTextStorage alloc]init];\ntextStorage.range = [text rangeOfString:@\"总有一天你将破蛹而出\"]; \ntextStorage.textColor = RGB(0, 155, 0, 1);\ntextStorage.font = [UIFont systemFontOfSize:18];\n[label addTextStorage:textStorage];\n\n[label addLinkWithLinkData:@\"www.baidu.com\" range:NSMakeRange(5, 8)];\n\n[label addImageWithName:@\"haha\" range:NSMakeRange(2, 1)];\n\nUIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"CYLoLi\"]];\nimageView.frame = CGRectMake(0, 0, CGRectGetWidth(label.frame), 180);\n[label addView:imageView range:NSMakeRange(16, 1)];\n\n[label sizeToFit];\n\n```\n\n* **TextContainer demo**\n```objc\nNSString *text = @\"\\t总有一天你将破蛹而出，成长得比人们期待的还要美丽。\\n\";\nTYTextContainer *textContainer = [[TYTextContainer alloc]init];\n    textContainer.text = text;\n    // 文字间隙\ntextContainer.characterSpacing = 2;\n// 文本行间隙\ntextContainer.linesSpacing = 5;\n\ntextStorage = [[TYTextStorage alloc]init];\ntextStorage.range = [text rangeOfString:@\"总有一天你将破蛹而出\"]; \ntextStorage.textColor = RGB(0, 155, 0, 1);\ntextStorage.font = [UIFont systemFontOfSize:18];\n[textContainer addTextStorage:textStorage];\n\n[textContainer addLinkWithLinkData:@\"www.baidu.com\" range:NSMakeRange(5, 8)];\n\n[textContainer addImageWithName:@\"haha\" range:NSMakeRange(2, 1)];\n\nUIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@\"CYLoLi\"]];\nimageView.frame = CGRectMake(0, 0, CGRectGetWidth(label.frame), 180);\n[textContainer addView:imageView range:NSMakeRange(16, 1)];\n\n\n// 生成 textContainer 文本容器\n[textContainer createTextContainerWithTextWidth:CGRectGetWidth(self.view.frame)];\n\nTYAttributedLabel *label = [[TYAttributedLabel alloc]init];\nlabel.textContainer = textContainer;\n\n\n// 也可以 生成NSAttributedString 属性文本\n//NSAttributedString *attString = [textContainer createAttributedString];\n//label.attributedText = attString;\n\n[label setFrameWithOrign:CGPointZero Width:CGRectGetWidth(self.view.frame)];\n[self.view addSubView:label];\n```\n\n### Contact\n如果你发现bug，please pull reqeust me \u003cbr\u003e\n如果你有更好的改进，please pull reqeust me \u003cbr\u003e\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n \n \n \n \n \n \n \n\n[image-1]:\thttps://raw.githubusercontent.com/12207480/TYAttributedLabel/master/screenshot/TYAtrributedLabelDemo.gif\n[image-2]:\thttps://raw.githubusercontent.com/12207480/TYAttributedLabel/master/screenshot/weibo.gif\n[image-3]:\thttps://raw.githubusercontent.com/12207480/TYAttributedLabel/master/screenshot/DoExam.gif\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F12207480%2Ftyattributedlabel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F12207480%2Ftyattributedlabel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F12207480%2Ftyattributedlabel/lists"}