FHHTagView 1.0.4

FHHTagView 1.0.4

002and001 维护。



FHHTagView

License MIT  CocoaPods  CocoaPods 

安装

CocoaPods

  1. pod "FHHTagView" 添加到您的 Podfile。
  2. 运行 pod installpod update
  3. 导入 <FHHTagView/FHHTagView.h>。

手动

  1. FHHTagView 目录下的所有源文件拖到您的项目中
  2. 导入主头文件:#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];

示例:


FHHtagViewGif.gif

示例代码部分

- (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;
}