RESideMenu第三方storyboard的使用方法

RESideMenu第三方storyboard的使用方法ide

step1atom

建立一個繼承於RESideMenu的子類Viewcontrollerspa

RootViewController。h #import "RESideMenu.h" @interface RootViewController : RESideMenu @end

在storyboard中關聯RootViewController, 並將其設置爲根視圖code

step 2blog

在storyboard中添加一個navigation Controller和Viewcontroller,而且給navigation Controller添加storyboard ID, 點擊item按住鼠標右鍵拖拽,選中presentleftMenuViewController, 點擊item時就會出現抽屜效果繼承

 

 

step 3ci

在storyboard中添加一個viewcontroller, 做爲抽屜展現的視圖,添加添加storyboard IDit

step4io

最後在RootViewcontroller.m中添加代碼就能實現抽屜效果table

#import "RootViewController.h" #import "ViewController.h" #import "RESideMenu.h" @interface RootViewController ()<RESideMenuDelegate> @end @implementation RootViewController - (void)awakeFromNib { self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"]; // self.contentViewController = self; self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuViewController"]; self.menuPreferredStatusBarStyle = UIStatusBarStyleLightContent; self.contentViewShadowColor = [UIColor blackColor]; self.contentViewShadowOffset = CGSizeMake(0, 0); self.contentViewShadowOpacity = 0.6; self.contentViewShadowRadius = 12; self.contentViewShadowEnabled = NO; // self.rightMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"rightMenuViewController"]; }

效果圖:

注: leftViewController能夠是一個tableView,點擊跳轉頁面效果將contentViewController改變便可, 關鍵實現代碼

@interface DEMOLeftMenuViewController () @property (strong, readwrite, nonatomic) UITableView *tableView; @end @implementation DEMOLeftMenuViewController - (void)viewDidLoad { [super viewDidLoad]; self.tableView = ({ UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, (self.view.frame.size.height - 54 * 5) / 2.0f, self.view.frame.size.width, 54 * 5) style:UITableViewStylePlain]; tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth; tableView.delegate = self; tableView.dataSource = self; tableView.opaque = NO; tableView.backgroundColor = [UIColor clearColor]; tableView.backgroundView = nil; tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.bounces = NO; tableView.scrollsToTop = NO; tableView; }); [self.view addSubview:self.tableView]; } #pragma mark - #pragma mark UITableView Delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; switch (indexPath.row) { case 0: [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"firstViewController"]] animated:YES]; [self.sideMenuViewController hideMenuViewController]; break; case 1: [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"secondViewController"]] animated:YES]; [self.sideMenuViewController hideMenuViewController]; break; default: break; } } #pragma mark - #pragma mark UITableView Datasource - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 54; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionIndex { return 5; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; cell.backgroundColor = [UIColor clearColor]; cell.textLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:21]; cell.textLabel.textColor = [UIColor whiteColor]; cell.textLabel.highlightedTextColor = [UIColor lightGrayColor]; cell.selectedBackgroundView = [[UIView alloc] init]; } NSArray *titles = @[@"Home", @"Calendar", @"Profile", @"Settings", @"Log Out"]; NSArray *images = @[@"IconHome", @"IconCalendar", @"IconProfile", @"IconSettings", @"IconEmpty"]; cell.textLabel.text = titles[indexPath.row]; cell.imageView.image = [UIImage imageNamed:images[indexPath.row]]; return cell; }
相關文章
相關標籤/搜索