Coder Social home page Coder Social logo

zwcshy / tyattributedlabel Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 12207480/tyattributedlabel

0.0 1.0 0.0 1.9 MB

TYAttributedLabel 简单易用的属性文本控件(无需了解CoreText),支持富文本,图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示

Objective-C 100.00%

tyattributedlabel's Introduction

TYAttributedLabel

TYAttributedLabel 简单易用的属性文本的控件(无需了解CoreText),支持富文本,图文混排显示,支持添加链接,image和UIView控件,支持自定义排版显示,

ScreenShot

image

Requirements

  • Xcode 5 or higher
  • Apple LLVM compiler
  • iOS 6.0 or higher
  • ARC

Features

  • 支持富文本,图文混排显示,支持行间距 字间距,自适应高度
  • 支持添加高度自定义文本属性
  • 支持添加属性文本,自定义链接,新增高亮效果显示(文字和背景)
  • 支持添加UIImage和UIView控件

Update

v1.1 添加链接高亮效果,链接便利方法,长按手势代理,优化代码

Demo

运行demo可以查看效果,而且在demo中有详细的例子,针对各种文本和图文的实现,这里简单的介绍下用法

Usage

API Quickstart

  • Category And Protocol
Class Function
NSMutableAttributedString (TY) category提供便利color,font CharacterSpacing,UnderlineStyle,ParagraphStyle的属性添加,无需了解复杂的CoreText
TYTextStorageProtocol 自定义文本属性 遵守最基本的协议 即可 addTextStorage 添加进去
TYAppendTextStorageProtocol 自定义文本属性协议 遵守即可appendTextStorage 添加进去
TYDrawStorageProtocol 自定义显示内容协议 如 UIImage UIView

下层协议继承上层的协议,如果觉得复杂,其实我已经实现了常用的自定义属性,拿来就可以用,或者继承,添加你想要的

  • Label And Storage
Class Function
TYAttributedLabel 简单易用的属性文本,富文本的显示控件,
addTextStorage在已经设置文本的基础上添加属性,image或者view,
appendTextStorage(无需事先设置文本)直接添加属性,image或者view到最后
TYTextStorage 自定义文本属性,支持textColor,font,underLineStyle
TYLinkTextStorage 自定义链接属性,继承TYTextStorage,支持点击代理
TYDrawStorage 自定义显示内容属性,如UIImage,UIView,支持点击代理
TYImageStorage 自定义图片显示,继承TYDrawStorage
TYViewStorage 自定义UIView控件,继承TYDrawStorage

如果需要更加详细的内容,请看各个头文件,有详细的注释

Delegate

// 点击代理
- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageClicked:(id<TYTextStorageProtocol>)textStorage atPoint:(CGPoint)point;

// 长按代理 有多个状态 begin, changes, end 都会调用,所以需要判断状态
- (void)attributedLabel:(TYAttributedLabel *)attributedLabel textStorageLongPressed:(id<TYTextStorageProtocol>)textStorage onState:(UIGestureRecognizerState)state atPoint:(CGPoint)point;

Examples

TYAttributedLabel *label = [[TYAttributedLabel alloc]init];
[self.view addSubview:label];

NSString *text = @"\t总有一天你将破蛹而出,成长得比人们期待的还要美丽。\n";
[label appendText:text];

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:text];
[attributedString addAttributeTextColor:[UIColor blueColor]];
[attributedString addAttributeFont:[UIFont systemFontOfSize:15]];
[label appendTextAttributedString:attributedString];

[label appendImageWithName:@"CYLoLi" size:CGSizeMake(CGRectGetWidth(label.frame), 180)];

UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"CYLoLi"]];
imageView.frame = CGRectMake(0, 0, CGRectGetWidth(label.frame), 180);
[label appendView:imageView];

[label setFrameWithOrign:CGPointMake(0,0Width:CGRectGetWidth(self.view.frame)];

Contact

如果你发现bug,please pull reqeust me
如果你有更好的想法或者建议可以联系我,Email:[email protected]

tyattributedlabel's People

Contributors

12207480 avatar

Watchers

周文超 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.