Git Product home page Git Product logo

fmtagsview's Introduction

FMTagsView

LICENSE Version CocoaPods

一个基于UICollectionView的标签展示控件

Screenshots

  1. 示例一,仿天猫热门搜索标签的效果: Hot Search.gif

  2. 实例二,动态添加和删除标签

动态添加和删除.gif

Features

  • 支持AutoLayout
  • 支持自定义Tag的外观,如圆角,背景颜色,标签文字颜色...
  • 支持动态添加和删除Tag
  • 支持单选和多选模式

How to Use

首先,添加 FMTagsView.h 和 FMTagsView.m 这两个文件到你项目中,或者使用pod来安装。

pod 'FMTagsView'

控件初始化示例:

  FMTagsView *tagsView = [[FMTagsView alloc] initWithFrame:CGRectMake(10, 120, 300, 150)];
    tagsView.contentInsets = UIEdgeInsetsZero;
    tagsView.tagInsets = UIEdgeInsetsMake(5, 15, 5, 15);
    tagsView.tagBorderWidth = 1;
    tagsView.tagcornerRadius = 2;
    tagsView.tagBorderColor = [UIColor lightGrayColor];
    tagsView.tagSelectedBorderColor = [UIColor lightGrayColor];
    tagsView.tagBackgroundColor = [UIColor whiteColor];
    tagsView.lineSpacing = 10;
    tagsView.interitemSpacing = 10;
    tagsView.tagFont = [UIFont systemFontOfSize:14];
    tagsView.tagTextColor = [UIColor grayColor];
    tagsView.delegate = self;
    [self.view addSubview:tagsView];
    
    NSArray *dataArray = @[@"麻棉连衣裙", @"面条", @"亲子装",
                       @"卫生巾", @"米", @"眉笔", @"蛋糕",
                       @"面包", @"洗洁精", @"咖啡速溶",
                       @"云南白药牙膏", @"方便面", @"空调"];
    //设置数据源
    tagsView.tagsArray = dataArray;

实现代理方法:

//点击标签处理逻辑
- (void)tagsView:(FMTagsView *)tagsView didSelectTagAtIndex:(NSUInteger)index {
    NSString *selectedKey = self.dataArray[index];
    UIViewController *controller = [[UIViewController alloc] init];
    controller.view.backgroundColor = [UIColor whiteColor];
    controller.title = selectedKey;
    [self.navigationController pushViewController:controller animated:YES];
}

fmtagsview's People

Contributors

lexiaoyao20 avatar

Stargazers

Wonhee Son avatar  avatar 小码歌 avatar JoeyShum avatar Been avatar  avatar jinleliao avatar rey avatar 火之玉 avatar Kevin avatar  avatar  avatar  avatar NSLegend avatar ym avatar ducai avatar Shadow avatar Damon avatar Lennon avatar  avatar 屋檐上的猫 avatar RUI7 avatar baipeng avatar iVikings avatar TableView avatar  avatar  avatar  avatar  avatar Evan avatar  avatar Gg avatar  avatar zlcode avatar MKGH avatar 水中树叶 avatar openShu avatar kim4apple avatar 胡定锋 avatar  avatar  avatar  avatar ZuiHongChen avatar LinAB avatar GIKI avatar  avatar  avatar 狼凤皇 avatar  avatar MWCao avatar HuangMS-War avatar yeelight-牛星华 avatar Huang avatar  avatar Master's Brother avatar Kai Li avatar  avatar  avatar winton avatar Pulan avatar aron1992 avatar  avatar MaNing avatar  avatar  avatar  avatar 晋先森 avatar Kevin avatar  avatar

Watchers

 avatar

fmtagsview's Issues

- (BOOL)tagsView:(FMTagsView *)tagsView shouldDeselectItemAtIndex:(NSUInteger)index;不执行

  • (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(tagsView:didDeSelectTagAtIndex:)]) {
    return [self.delegate tagsView:self shouldDeselectItemAtIndex:indexPath.row];
    }
    return YES;
    }
  • (BOOL)collectionView:(UICollectionView *)collectionView shouldDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(tagsView:shouldDeselectItemAtIndex:)]) {
    return [self.delegate tagsView:self shouldDeselectItemAtIndex:indexPath.row];
    }
    return YES;
    }

The frame height doesn't adjust after layoutIfNeeded

Still learning objective c, but apparently once you set the frame with

FMTagsView *tagsView = [[FMTagsView alloc] initWithFrame:CGRectMake(10, 10, 320, 190)];

the frame doesn't autoadjust to the right height when you set

[tagsView layoutIfNeeded];

or

UICollectionView *collectionView = tagsView.subviews.firstObject;
[collectionView layoutIfNeeded];

Why is that?

添加频道功能

这个库确实挺实用的,能否拓展到频道管理,类似网易新闻、今日头条、一点资讯,拥有长按排序功能,在点击更多频道会添加到我的频道中,希望完成之后拓展demo。

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.