CYDropDownMenu 1.0.2

CYDropDownMenu 1.0.2

Yun CHEN 维护。




  • 作者
  • Yun CHEN

CYDropDownMenu

简体中文

iOS 下拉菜单。它与桌面应用程序的菜单非常相似。截图

CYDropDownMenu

安装

CocoaPods

使用 CocoaPods 将 CYDropDownMenu 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

platform :ios, '8.0'
use_frameworks!

target 'YourProjectName' do
   pod 'CYDropDownMenu', '~> 1.0.1'
end

对于 Swift,记得在使用它之前使用 import CYDropDownMenu 模块。

手动安装

/CYDropDownMenu 文件夹中的源代码复制到您的项目中。

使用方法

就像使用 UIView 一样来使用它。你可以在示例项目中找到更多关于如何使用的详细信息。

创建 CYDropDownMenu 并设置数据

CGFloat navigationBarHeight = ([UIApplication sharedApplication].statusBarFrame.size.height + (self.navigationController.navigationBar.frame.size.height ?: 0.0));
    
CYDropDownMenu *dropDownMenu = [[CYDropDownMenu alloc] initWithFrame:CGRectMake(0, navigationBarHeight, self.view.frame.size.width, 45)];
dropDownMenu.sectionTitles = @[@"Category", @"Price", @"Distance", @"Order", @"More"];
dropDownMenu.sectionsItems = @[@[@"All",@"Food", @"Hotel", @"Bank", @"Cinema", @"Entertainment"],
                                @[@"$0", @"$1-$100", @"$101-$1000", @">$1000"],
                                @[@"0-10km", @"11-100km", @"101-1000km", @">1000km"],
                                @[@"Recommended", @"Near to me", @"The highest sales", @"Hots"],
                                @[@"24 Hours", @"Available in Holidays"]];
dropDownMenu.autoCenterTitles = YES; //for the case there are only 1 or 2 titles, we center them.
dropDownMenu.delegate = self;
[self.view addSubview:dropDownMenu];

自定义(可选)

// Additional customizations:
dropDownMenu.sectionTitleColor = UIColor.lightGrayColor;  //The color of top titles
dropDownMenu.sectionTitleTintColor = UIColor.redColor;    //The color of top selected titles
dropDownMenu.itemColor = UIColor.lightGrayColor;          //The color of menu item
dropDownMenu.itemTintColor = UIColor.redColor;            //The color of selected menu item
dropDownMenu.bottomLineHidden = YES;                      //Indicates whether display the bottom line
dropDownMenu.maxMenuHeight = 100;                         //Keep this to nil usually. The Menu height is automatically calculated, and limited in rootview's height. Set this property if you want to limit the height precisely.
dropDownMenu.rootView = self.view;                        //Keep this to nil usually. The ViewController's view will be considered as rootView if the property is not set. Set this property to limite the DropDownMenu and its actions into a particular SubView.

处理事件

#pragma mark - CYDropDownMenuDelegate
- (void)CYDropDownMenu:(CYDropDownMenu *)dropDownMenu didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"Menu item '%@' of section '%@' is selected",dropDownMenu.sectionsItems[indexPath.section][indexPath.row], dropDownMenu.sectionTitles[indexPath.section]);
}

针对 Swift

我们建议使用 CocoaPods 将库集成到你的项目中。然后像这样代码:

import UIKit
import CYDropDownMenu

class ViewController: UIViewController,CYDropDownMenuDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let topbarHeight = UIApplication.shared.statusBarFrame.size.height + (self.navigationController != nil ? self.navigationController!.navigationBar.frame.size.height : CGFloat(0.0))
        let dropDownMenu = CYDropDownMenu(frame: CGRect(x: 0.0, y: topbarHeight, width: self.view.frame.size.width, height: 45.0))
        dropDownMenu.sectionTitles = ["Category", "Price"];
        dropDownMenu.sectionsItems = [["All","Food", "Hotel", "Bank", "Cinema", "Entertainment"],
                                      ["$0", "$1-$100", "$101-$1000", ">$1000"]];
        dropDownMenu.autoCenterTitles = true
        dropDownMenu.delegate = self
        
        self.view.addSubview(dropDownMenu);
    }

    // MARK: CYDropDownMenuDelegate
    func cyDropDownMenu(_ dropDownMenu: CYDropDownMenu!, didSelectItemAt indexPath: IndexPath!) {
        print("Menu item '\(dropDownMenu.sectionsItems[indexPath.section][indexPath.row])' of section '\(dropDownMenu.sectionTitles[indexPath.section])' is selected")
    }
}

许可证

CYDropDownMenu 在 MIT 许可下发布。详情请见 LICENSE 文件。