Latest 0.1
Homepage https://github.com/botherbox/SGFilterView
License Apache
Platforms ios 7.0
Frameworks UIKit
Authors

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

Latest podspec

{
    "name": "SGFilterView",
    "version": "0.1",
    "summary": "A lightweight drop down filter menu with simple APIs",
    "description": "A lightweight drop down filter menu with simple APIs; u7b80u6d01u7684u4e0bu62c9u7b5bu9009u83dcu5355uff0cu4f7fu7528u8d77u6765u5f88u7b80u5355uff0cu540cu65f6u4e5fu5f88u5bb9u6613u6269u5c55",
    "homepage": "https://github.com/botherbox/SGFilterView",
    "license": "Apache",
    "authors": {
        "botherbox": "[email protected]"
    },
    "platforms": {
        "ios": "7.0"
    },
    "source": {
        "git": "https://github.com/botherbox/SGFilterView.git",
        "tag": "v0.1"
    },
    "source_files": [
        "SGFilterView",
        "SGFilterView/**/*.{h,m}"
    ],
    "resources": "SGFilterView/SGFilterView.bundle",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This