IGCMenu
IGCMenu库为创建应用中的 网格 和 圆形 菜单提供了简单的方法。
这是一个轻量级且高度可定制的菜单。支持iOS 7及以上版本。
对于Swift,检查swift分支
网格菜单 | 圆形菜单 |
---|---|
![]() |
![]() |
模糊背景 | |
![]() |
功能
- 网格菜单
- 圆形菜单
- 模糊背景
- 启用/禁用菜单背景
- 菜单项可以没有图像/名称
安装
使用CocoaPods进行安装
您可以通过将IGCMenu添加到您的Podfile中使用CocoaPods来安装它。
platform :ios, '8.0'
target 'TargetName' do
pod 'IGCMenu'
end
然后,运行以下命令
$ pod install
手动操作
将“IGCMenu”文件夹与其源文件一起拖入您的项目中。
使用方法
导入
#import "IGCMenu.h"
符合协议
可选 如果您不想在菜单项选择时接收通知,则可跳过此步骤。
符合IGCMenuDelegate
@interface ViewController : UIViewController<IGCMenuDelegate>
创建实例变量
创建IGCMenu类型的实例变量。
@implementation ViewController{
IGCMenu *igcMenu;
}
创建IGCMenu类实例并配置属性
if (igcMenu == nil) {
igcMenu = [[IGCMenu alloc] init];
}
igcMenu.menuButton = self.menuButton; //Pass refernce of menu button
igcMenu.menuSuperView = self.view; //Pass reference of menu button super view
igcMenu.disableBackground = YES; //Enable/disable menu background
igcMenu.numberOfMenuItem = 5; //Number of menu items to display
//Menu background. It can be BlurEffectExtraLight,BlurEffectLight,BlurEffectDark,Dark or None
igcMenu.backgroundType = BlurEffectDark;
/* Optional
Pass name of menu items
**/
igcMenu.menuItemsNameArray = [NSArray arrayWithObjects:@"Home",@"Like",@"Search",@"User",@"Buy",nil];
/*Optional
Pass color of menu items
**/
UIColor *homeBackgroundColor = [UIColor colorWithRed:(33/255.0) green:(180/255.0) blue:(227/255.0) alpha:1.0];
UIColor *searchBackgroundColor = [UIColor colorWithRed:(139/255.0) green:(116/255.0) blue:(240/255.0) alpha:1.0];
UIColor *favoritesBackgroundColor = [UIColor colorWithRed:(241/255.0) green:(118/255.0) blue:(121/255.0) alpha:1.0];
UIColor *userBackgroundColor = [UIColor colorWithRed:(184/255.0) green:(204/255.0) blue:(207/255.0) alpha:1.0];
UIColor *buyBackgroundColor = [UIColor colorWithRed:(169/255.0) green:(59/255.0) blue:(188/255.0) alpha:1.0];
igcMenu.menuBackgroundColorsArray = [NSArray arrayWithObjects:homeBackgroundColor,favoritesBackgroundColor,searchBackgroundColor,userBackgroundColor, buyBackgroundColor,nil];
/*Optional
Pass menu items icons
**/
igcMenu.menuImagesNameArray = [NSArray arrayWithObjects:@"home.png",@"favourite.png",@"search.png",@"user.png",@"buy.png",nil];
/*Optional if you don't want to get notify for menu items selection
conform delegate
**/
igcMenu.delegate = self;
名称、颜色和图标数组将按相同顺序显示。
显示/隐藏菜单
在菜单按钮按下时,您可以通过调用以下方法来显示或隐藏菜单项。
显示/隐藏圆形菜单
[igcMenu showCircularMenu]; //Show circular menu
[igcMenu hideCircularMenu]; //Hide circular menu
显示/隐藏 网格菜单
[igcMenu showGridMenu]; //Show grid menu
[igcMenu hideGridMenu]; //Hide grid menu
代理实现
若想获得关于菜单项选择的通知,你必须实现此方法。
- (void)igcMenuSelected:(NSString *)selectedMenuName atIndex:(NSInteger)index{
//Perform any action on selection of menu item
}
选择任何菜单项时返回选定菜单项的名称(如果有,否则为nil)和菜单项的索引。菜单项的索引从0开始。
自定义
@property (nonatomic) NSInteger numberOfMenuItem; //Number of menu items to show
@property (nonatomic) CGFloat menuRadius; //Radius for circular menu
@property (weak,nonatomic) UIButton *menuButton; //Menu button reference
@property (weak,nonatomic) UIView *menuSuperView; //Menu button super view reference
@property (strong,nonatomic) NSArray *menuItemsNameArray; //Menu items name array,it can be empty
@property (strong,nonatomic) NSArray *menuBackgroundColorsArray; //Menu items background color,it can be empty, default color is white
@property (strong,nonatomic) NSArray *menuImagesNameArray; //Menu item icons array it can be empty
@property (nonatomic) BOOL disableBackground; //Disable background view, default is TRUE
@property int maxColumn; //Maximium number of column,default is 3
@property int menuHeight; //height = width ,default is 65
/*
Set menu background.It can be BlurEffectExtraLight,BlurEffectLight,BlurEffectDark,Dark or None.
Default is BlurEffectDark.
*/
@property IGCMenuBackgroundOptions backgroundType;
注意
此库不会自定义菜单按钮(例如示例底部深蓝色背景色)如使其圆润、设置背景色、更改图标(如+和x)。这留给你来自定义。如有需要,可以参考示例。使按钮圆形的代码如下:
self.menuButton.clipsToBounds = YES;
self.menuButton.layer.cornerRadius = self.menuButton.frame.size.height/2;
让我们知道吧!
如果您能向我们发送您使用我们库的项目链接,我们将非常高兴。如果您有任何关于此类的事情的疑问或建议,也请告知我们。
许可证
IGCMenu 按照MIT许可证提供。