First of all add mfsidemenu folder in your project and also images folder. After adding this both things you have to make one sidemenuviewcontroller for you want to display menu in it.
Now make one view controller and add this code snippets in your file . Here i am giving files as per my project.
SidemenuViewController.h
#import <UIKit/UIKit.h>SidemenuViewController.m
@interface SideMenuViewController : UIViewController
@end
#import "SideMenuViewController.h"
#import "MFSideMenu/MFSideMenuContainerViewController.h"
@interface SideMenuViewController ()
@end
@implementation SideMenuViewController
- (MFSideMenuContainerViewController *)menuContainerViewController {
return (MFSideMenuContainerViewController *)self.parentViewController;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Now your xib file where you want to display menu.
ViewController.h
#import <UIKit/UIKit.h>ViewController.m
@interface ViewController : UIViewController
@end
#import "ViewController.h"
#import "MFSideMenu/MFSideMenuContainerViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupMenuBarButtonItems];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (MFSideMenuContainerViewController *)menuContainerViewController {
return (MFSideMenuContainerViewController *)self.navigationController.parentViewController;
}
#pragma mark -
#pragma mark - UIBarButtonItems
- (void)setupMenuBarButtonItems {
self.navigationItem.rightBarButtonItem = [self rightMenuBarButtonItem];
if(self.menuContainerViewController.menuState == MFSideMenuStateClosed &&
![[self.navigationController.viewControllers objectAtIndex:0] isEqual:self]) {
self.navigationItem.leftBarButtonItem = [self backBarButtonItem];
} else {
self.navigationItem.leftBarButtonItem = [self leftMenuBarButtonItem];
}
}
- (UIBarButtonItem *)leftMenuBarButtonItem {
return [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"menu-icon.png"] style:UIBarButtonItemStyleBordered
target:self
action:@selector(leftSideMenuButtonPressed:)];
}
- (UIBarButtonItem *)rightMenuBarButtonItem {
return [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"menu-icon.png"] style:UIBarButtonItemStyleBordered
target:self
action:@selector(rightSideMenuButtonPressed:)];
}
- (UIBarButtonItem *)backBarButtonItem {
return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back-arrow"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backButtonPressed:)];
}
#pragma mark -
#pragma mark - UIBarButtonItem Callbacks
- (void)backButtonPressed:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)leftSideMenuButtonPressed:(id)sender {
[self.menuContainerViewController toggleLeftSideMenuCompletion:^{
[self setupMenuBarButtonItems];
}];
}
- (void)rightSideMenuButtonPressed:(id)sender {
[self.menuContainerViewController toggleRightSideMenuCompletion:^{
[self setupMenuBarButtonItems];
}];
}
@end
Output Screens:
0 comments:
Post a Comment