From bc058cf72af6a8205692a601f8d15391f0a92d86 Mon Sep 17 00:00:00 2001 From: Alan Bithell Date: Thu, 3 Jan 2019 15:04:17 -0800 Subject: [PATCH] Added code to setMenuViewController to set the VC frame width from the SideBarStyle.menuWidth. Default to 75% screen width if style not set. Requires call to setSideBarStyle before setMenuViewController, but no longer requries view width to be set in storyboard --- LMSideBarController/LMSideBarController.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/LMSideBarController/LMSideBarController.m b/LMSideBarController/LMSideBarController.m index 6367d27..69431eb 100644 --- a/LMSideBarController/LMSideBarController.m +++ b/LMSideBarController/LMSideBarController.m @@ -154,16 +154,24 @@ - (void)setMenuViewController:(UIViewController *)menuViewController forDirectio // Add the new one [self.menuViewControllers setObject:menuViewController forKey:@(direction)]; + + // Get style for direction, use menuWidth as SideBar width + // Default to 75% view width + LMSideBarStyle *style = [self styleForDirection:direction]; + CGFloat width = style.menuWidth; + if(width == 0){ + width = self.view.bounds.size.width * 3.0/4.0; + } if (direction == LMSideBarControllerDirectionLeft) { - [self setupViewController:menuViewController frame:CGRectMake(-self.view.bounds.size.width, + [self setupViewController:menuViewController frame:CGRectMake(-width, 0, - self.view.bounds.size.width, + width, self.view.bounds.size.height)]; } else { [self setupViewController:menuViewController frame:CGRectMake(self.view.bounds.size.width, 0, - self.view.bounds.size.width, + width, self.view.bounds.size.height)]; } menuViewController.view.hidden = YES;