FHHTagView
安装
CocoaPods
- 将
pod "FHHTagView"
添加到您的 Podfile。
- 运行
pod install
或 pod update
。
- 导入 <FHHTagView/FHHTagView.h>。
手动
- 将
FHHTagView
目录下的所有源文件拖到您的项目中
- 导入主头文件:
#import "FHHTagView.h"
提示:
- 支持高度计算API
- 自定义标签样式
- 支持标签视图选择样式
- 在标签被选中时支持上块
- 提供添加、插入、删除操作
简介
如何使用
NSMuatbleArray<FHHTag *> *tagArray = [[NSMuatbleArray<FHHTag *> alloc] init];
FHHTag *tag = [[FHHTag alloc] initWithTitle:@"Big Hero 6"];
[tagArray addObject:tag];
FHHTagViewLayout *layout = [[FHHTagViewLayout alloc] init];
layout.width = 300;
layout.lineSpacing = 5.0;
layout.innerItemSpacing = 4.0;
- 初始化一个标签视图,然后调用函数 refreshWithTagArray:,如
FHHTagView *tagView = [[FHHTagView alloc] init];
[tagView refreshWithTagArray:tagArray layout:layout];
示例:

示例代码部分
- (void)p_configTagView {
NSArray *titleArray = @[@"Tatchi", @"DRAGON BALL", @"火影忍者", @"我家有个狐仙大人", @"进击的巨人", @"东京食尸鬼", @"ONE PUNCH-MAN", @"我叫坂本我最屌", @"四月是你的谎言", @"Angle beats", @"Charlotte", @"Fate", @"境界的彼方", @"头脑特工队", @"从前有座灵剑山",@"一人之下", @"妖狐小红娘"];
NSMutableArray *tagArrayM = [NSMutableArray arrayWithCapacity:titleArray.count];
for (NSString *title in titleArray) {
FHHTag *tag = [self p_tagWithTitle:title];
if ([title isEqualToString:@"头脑特工队"]) {
tag.normalStateButtonBlock = ^(FHHTagButton *button) {
button.layer.borderColor = [[UIColor purpleColor] CGColor];
[button setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
};
}
[tagArrayM addObject:tag];
}
FHHTagViewLayout *layout = [[FHHTagViewLayout alloc] init];
_tagViewLayout = layout;
FHHTagView *tagView = [[FHHTagView alloc] init];
tagView.selectionStyle = FHHTagViewSelectionStyleSingle;
// tagView.selectionStyle = FHHTagViewSelectionStyleMutiple;
// tagView.selectionStyle = FHHTagViewSelectionStyleNone;
layout.width = 300;
layout.lineSpacing = 10.0;
layout.innerItemSpacing = 10.0;
// tagView.padding = UIEdgeInsetsMake(10, 5, 20, 0);
tagView.fhh_x = 10;
tagView.fhh_y = 50;
[tagView refreshWithTagArray:tagArrayM layout:layout];
[self.view addSubview:tagView];
- (FHHTag *)p_tagWithTitle:(NSString *)title {
FHHTag *tag = [[FHHTag alloc] initWithTitle:title];
tag.normalStateButtonBlock = ^(FHHTagButton *button) {
button.layer.borderColor = [[UIColor blackColor] CGColor];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
};
__weak typeof(tag) weakTag = tag;
tag.selectedStateButtonBlcok = ^(FHHTagButton *button) {
button.layer.borderColor = [[UIColor orangeColor] CGColor];
[button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
NSLog(@"tag.title:%@",weakTag.title);
};
tag.enable = true;
tag.cornerRadius = 3;
tag.borderWidth = 1.0;
tag.fontSize = 12;
tag.padding = UIEdgeInsetsMake(5, 5, 5, 5);
// tag.buttonHeight = 25.0; // will disable tag.padding
return tag;
}