Code Monkey home page Code Monkey logo

yffilterviewdemo's Introduction

YFFilterView -- iOS筛选控件

  • 使用Masonry布局,动态添加按钮数量,实现效果如图所示

  • Using Masonry layout. Dynamicly adding buttons.

Using -- 使用

Create -- 创建

通过正常的创建视图的方法创建即可YFFilterView *filterView = [[YFFilterView alloc] initWithFrame:frame]

Create by the normal way. YFFilterView *filterView = [[YFFilterView alloc] initWithFrame:frame]

Initialize -- 初始化

按钮根据传入的titleArray动态创建,在setupUIWithTitleArray方法执行后,视图元素才会被加载。

The button was created with titleArray. The view element was loaded after setupUIWithTitleArray method get called.

根据block中的btn.tag来判断第几个按钮被点击,从而进行相应的逻辑处理。

Get the selected index by btn.tag in the block. Implement the rest logic by yourself.

    [filterView setupUIWithTitleArray:@[@"目的地", @"旅行主题", @"旅行天数", @"hhh"].mutableCopy fontAttributes:nil handler:^(UIButton *btn) {
        NSLog(@"%ld", btn.tag);
        [self changeSelectionView:btn.tag];
        
    }];

由于按钮点击后的视图按需而变,故这里的逻辑留给coder自己处理。

Selection logic -- 选中逻辑处理

一般地,在选中筛选条件后,按钮标题会变为选中项。itemDidChosenWithTitle:atIndex:方法实现该逻辑,index为按钮的位置。

Generally, after selecting the condition. The title of that button would be changed to the selection item. itemDidChosenWithTitle:atIndex: this method implemented this logic & index was the button's index.

    [self.filterView itemDidChosenWithTitle:@"哈哈哈" atIndex:0];

Switching selection view -- 选中视图切换

使用视图隐藏的方式切换视图,视图的隐藏在YFFilterView中已封装,使用者只需在block中实现特定视图的显示即可。

Switching the view by hidden property.

- (void)changeSelectionView:(NSUInteger)index {
    switch (index) {
        case 0: {
            
            if (!self.firstView) {
                self.firstView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
                self.firstView.backgroundColor = [UIColor redColor];
                [self.filterView.bgView addSubview:self.firstView];
            }
            self.firstView.hidden = NO;
            
            [self.filterView itemDidChosenWithTitle:@"哈哈哈" atIndex:0];
            break;
        }
            
        case 1:{
            if (!self.secondView) {
                self.secondView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
                self.secondView.backgroundColor = [UIColor blueColor];
                [self.filterView.bgView addSubview:self.secondView];;
            }
            
            self.secondView.hidden = NO;
            break;
        }
            
        case 2: {
            if (!self.thirdView) {
                self.thirdView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
                self.thirdView.backgroundColor = [UIColor yellowColor];
                [self.filterView.bgView addSubview:self.thirdView];;
            }
            
            self.thirdView.hidden = NO;
            break;
        }
            
        default:
            break;
    }
}

Looking forwatd -- 期待

  • 如果在使用过程中遇到BUG,希望你能Issues我,谢谢(或者尝试下载最新的框架代码看看BUG修复没有)
  • Issue me if you find bug
  • 如果你想为YFFilterView输出代码,请拼命Pull Requests我
  • Pull Requests ME Desperately!

yffilterviewdemo's People

Contributors

zooyf 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.