Giter Site home page Giter Site logo

sgfilterview's Introduction

SGFilterView

A lightweight drop down filter menu with simple APIs 这是一个下拉筛选菜单,使用起来很简单

Usage

// 1⃣️ create a instance with -initWithFrame:titles method
SGFilterView *filter = [[SGFilterView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, 44) titles:@[@"FilterOne", @"FilterTwo", @"FilterThree"]];

// 2⃣️ add to super view
[self.view addSubview:filter];

// 3⃣️ config data source & delegate
filter.dataSource = self; // id<SGFilterViewDataSource>
filter.delegate = self; // id<SGFilterViewDelegate>

// 4⃣️ confirm to protocol
@interface SomeViewController () <SGFilterViewDataSource, SGFilterViewDelegate>


// 5⃣️ implement method in data source protocol 
#pragma mark - SGFilterViewDataSource

// like table's -numberOfSectionsInTableView:
// 每个Tab有几列
- (NSInteger)filterView:(SGFilterView *)filterView numberOfColumnForTab:(NSInteger)tab
{
    if (tab == 0) {
        return 2;
    }
    return 1;
}

// 第tab里的第column列的数据,previousRow表示该列的前一列选中的row
/*
self.pData= @[@"北京", @"上海", @"河北"];
self.cData = @[
               @[@"海淀区", @"朝阳区", @"西城区", @"丰台区"],
               @[@"浦东区", @"徐汇区", @"虹口区"],
               @[@"石家庄市", @"邯郸市", @"保定市"]
               ];

*/
- (NSArray *)filterView:(SGFilterView *)filterView dataForColumn:(NSInteger)column inTab:(NSInteger)tab previousSelectedRow:(NSInteger)previousRow
{
    if (tab == 0) {
        if (column == 0) {
            return self.pData;
        } else if (column == 1) {
            return self.cData[previousRow];
        }
    } else if (tab == 1)
    {
        return @[@"所有品牌", @"保利国际影院", @"星美国际影城", @"中影国际影城"];
    } else if (tab == 2)
    {
        return @[@"离我最近", @"好评优先", @"价格最低"];
    }
    return nil;
}

// @optional
// main list is left table
- (CGFloat)filterView:(SGFilterView *)filterView ratioForMainListInTab:(NSInteger)index
{
    if (index == 0) {
        return 1.0/3;
    }
    return 1.0;
}

// 6⃣️ delegate
#pragma mark - SGFilterViewDelegate

- (BOOL)filterView:(SGFilterView *)filterView shouldFoldingOnSelectedRow:(NSInteger)row forColumn:(NSInteger)column inTab:(NSInteger)tab
{
    BOOL foldback = YES;
    if (tab == 0) { // filter one
        if (column == 0) {
            foldback = NO; // 不收回
        }
        
    } else {
        foldback = YES;
        if (tab == 1) { // filter two
            
        } else if (tab == 2) // filter three
        {
            
        }
        
    }

    return foldback;
}

- (BOOL)filterView:(SGFilterView *)filterView shouldChangeTitleOnSelectRow:(NSInteger)row forColumn:(NSInteger)column inTab:(NSInteger)tab
{
    return YES;
}

screenshot

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.