登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

TTGTagCollectionView

[复制链接]
来自: AlonMessi 分类: iOS精品源码 上传时间: 2016-11-1 11:13:39
Tag:tag 标签 collentionView 自动布局 UILabel

项目介绍:

https://github.com/zekunyan/TTGTagCollectionView

TTGTagCollectionView

Screenshot

What

TTGTagCollectionView用于垂直或水平滚动视图显示出不同大小的标签视图。如果你只想显示文字标签,你可以使用TTGTagCollectionView代替,具有更简单的API。
它是高度可定制的,许多功能的文本标签可以配置,如标签的字体大小和背景颜色。

Features

*支持的文本标签和自定义视图标签。
*高度可定制
*垂直和水平滚动
*基于UICollectionView
*支持Autolayout intrinsiccontentsize
自动确定基于内容的高度尺寸

Requirements

iOS 7 and later.

Installation

CocoaPods

TTGTagCollectionView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "TTGTagCollectionView"

Carthage

You can use Carthage to install TTGTagCollectionView by adding it to your Cartfile:

github "zekunyan/TTGTagCollectionView"

Usage

TTGTextTagCollectionView

Use TTGTextTagCollectionView to show text tags.

Basic usage

TTGTextTagCollectionView *tagCollectionView = [[TTGTextTagCollectionView alloc] initWithFrame:CGRectMake(20, 20, 200, 200)];
[self.view addSubview:tagCollectionView];
[tagCollectionView addTags:@[@"TTG", @"Tag", @"collection", @"view"]];

Delegate

Conform the TTGTextTagCollectionViewDelegate protocol to get callback when you select the tag or content height changes.

@protocol TTGTextTagCollectionViewDelegate <NSObject>
@optional
- (void)textTagCollectionView:(TTGTextTagCollectionView *)textTagCollectionView didTapTag:(NSString *)tagText atIndex:(NSUInteger)index selected:(BOOL)selected;

- (void)textTagCollectionView:(TTGTextTagCollectionView *)textTagCollectionView updateContentSize:(CGSize)contentSize;
@end

Customization

// Define if the tag can be selected.
@property (assign, nonatomic) BOOL enableTagSelection;

// Text font
@property (strong, nonatomic) UIFont *tagTextFont;

// Text color
@property (strong, nonatomic) UIColor *tagTextColor;
@property (strong, nonatomic) UIColor *tagSelectedTextColor;

// Background color
@property (strong, nonatomic) UIColor *tagBackgroundColor;
@property (strong, nonatomic) UIColor *tagSelectedBackgroundColor;

// Corner radius
@property (assign, nonatomic) CGFloat tagCornerRadius;
@property (assign, nonatomic) CGFloat tagSelectedCornerRadius; // Default is tagCornerRadius

// Border
@property (assign, nonatomic) CGFloat tagBorderWidth;
@property (assign, nonatomic) CGFloat tagSelectedBorderWidth; // Default is tagBorderWidth
@property (strong, nonatomic) UIColor *tagBorderColor;
@property (strong, nonatomic) UIColor *tagSelectedBorderColor; // Default is tagBorderColor

// Extra space for width and height
@property (assign, nonatomic) CGSize extraSpace;

// Horizontal and veritical space between tags
@property (assign, nonatomic) CGFloat horizontalSpacing;
@property (assign, nonatomic) CGFloat verticalSpacing;

// Content size
@property (nonatomic, assign, readonly) CGSize contentSize;

// Scroll direction. Default is vertical
@property (nonatomic, assign) TTGTagCollectionScrollDirection scrollDirection;

// Number of lines for horizontal direction
@property (nonatomic, assign) NSUInteger numberOfLinesForHorizontalScrollDirection;

// Tag shadow
@property (nonatomic, copy) UIColor *shadowColor; // Default is [UIColor black]
@property (nonatomic, assign) CGSize shadowOffset; // Default is CGSizeZero
@property (nonatomic, assign) CGFloat shadowRadius; // Default is 0f
@property (nonatomic, assign) CGFloat shadowOpacity; // Default is 0.5f

// Content inset, default is UIEdgeInsetsMake(2, 2, 2, 2)
@property (nonatomic, assign) UIEdgeInsets contentInset;

Config tags

// Add tags
- (void)addTag:(NSString *)tag;

- (void)addTags:(NSArray <NSString *> *)tags;

/// Remove tags
- (void)removeTag:(NSString *)tag;

- (void)removeTagAtIndex:(NSUInteger)index;

- (void)removeAllTags;

Config tag selection

- (void)setTagAtIndex:(NSUInteger)index selected:(BOOL)selected;

Get tag information

- (NSArray <NSString *> *)allTags;

- (NSArray <NSString *> *)allSelectedTags;

- (NSArray <NSString *> *)allNotSelectedTags;

Reload

You can reload tags programmatically.

- (void)reload;

TTGTagCollectionView

Use TTGTagCollectionView to show custom tag views.

DataSource and Delegate

Just like the UITableView, you must conform and implement the required methods of TTGTagCollectionViewDelegate and TTGTagCollectionViewDataSource to get TTGTagCollectionView work.

DataSource

@protocol TTGTagCollectionViewDataSource <NSObject>
@required
- (NSUInteger)numberOfTagsInTagCollectionView:(TTGTagCollectionView *)tagCollectionView;

- (UIView *)tagCollectionView:(TTGTagCollectionView *)tagCollectionView tagViewForIndex:(NSUInteger)index;
@end

Delegate

@protocol TTGTagCollectionViewDelegate <NSObject>
@required
- (CGSize)tagCollectionView:(TTGTagCollectionView *)tagCollectionView sizeForTagAtIndex:(NSUInteger)index;

@optional
- (void)tagCollectionView:(TTGTagCollectionView *)tagCollectionView didSelectTag:(UIView *)tagView atIndex:(NSUInteger)index;

- (void)tagCollectionView:(TTGTagCollectionView *)tagCollectionView updateContentSize:(CGSize)contentSize;
@end

Customization

You can config the horizontal and vertical space between tags.

/**
 * Tags scroll direction, default is veritical
 */
@property (nonatomic, assign) TTGTagCollectionScrollDirection scrollDirection;

/**
 * Number of lines for horizontal scroll direction
 */
@property (nonatomic, assign) NSUInteger numberOfLinesForHorizontalScrollDirection;

/**
 * Horizontal space between tags
 */
@property (nonatomic, assign) CGFloat horizontalSpacing;

/**
 * Vertical space between tags
 */
@property (nonatomic, assign) CGFloat verticalSpacing;

/**
 * The true tags content size
 */
@property (nonatomic, assign, readonly) CGSize contentSize;

/**
 * Tag shadow
 */
@property (nonatomic, strong) UIColor *shadowColor; // Default is [UIColor black]
@property (nonatomic, assign) CGSize shadowOffset; // Default is CGSizeZero
@property (nonatomic, assign) CGFloat shadowRadius; // Default is 0f
@property (nonatomic, assign) CGFloat shadowOpacity; // Default is 0.5f

/**
 * Content inset, default is UIEdgeInsetsMake(2, 2, 2, 2)
 */
@property (nonatomic, assign) UIEdgeInsets contentInset;

Reload

You can reload tags programmatically.

- (void)reload;

code4app

相关源码推荐:

我来说两句
*滑动验证:
所有评论(142)
kengsir 2016-11-1 15:14:30
code4app确实是个好地方,必须支持~
回复
BlueManlove 2016-11-1 17:58:35
好好 学习了 确实不错
回复
littleRed 2016-11-1 18:02:39
mark,收藏了
回复
phoiu 2016-11-1 18:05:49
相当不错,感谢无私分享精神!
回复
hellokenken 2016-11-1 18:17:08
学习...学习...
回复
code4app热心网友 2016-11-2 08:17:59
楼主威武啊,Code4App有你更给力!
回复
pchy苒 2016-11-2 09:08:04
楼主用心了,内容非常精彩。
回复
code4app热心网友 2016-11-2 10:08:33
很给力,Code4App有你更精彩!
回复
亚洲龙哥 2016-11-2 11:17:14
学习学习!
回复
提取码:  下载次数:144 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
1277 0 144
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表