I have created a custom navigation drawer in swift. I have used the window from app delegate & added a view on winddow. After i hide show the view on button click.
Below code to create drawer.
func setupSideMenu(){
windowSideMenu = ((UIApplication.shared.delegate?.window)!)!
windowSideMenu.backgroundColor = UIColor.black
if customView == nil {
print("custom view nil")
// Register Swipe gesture for opening slideMenu
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.openSideMenu))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
/// Register Drawable NIB here only for once
customView = SideView.instanceFromNib() as! SideView
customView.configureDrawer()
customView.navigationController = self.navigationController
customView.frame = CGRect(x: -customView.frame.size.width, y: -10, width: self.view.bounds.size.width - 30, height:UIScreen.main.bounds.height)
customView.drawerDelegate = self
/// BackView (DimView)
backView.frame = self.view.frame
backView.backgroundColor = UIColor.black
backView.alpha = 0.4
backView.isHidden = true
self.view.addSubview(backView)
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.closeSideMenu))
backView.addGestureRecognizer(tapGesture)
customView.isHidden = true
windowSideMenu.addSubview(customView)
windowSideMenu.makeKeyAndVisible()
}
}
On hide & show i change the window level UIWindowLevel
.
override func openSideMenu() {
super.openSideMenu()
self.windowSideMenu.windowLevel = UIWindowLevelStatusBar
}
override func closeSideMenu() {
super.closeSideMenu()
self.windowSideMenu.windowLevel = UIWindowLevelNormal
}
But when i change the windowlevel to UIWindowLevelStatusBar
then the color of status bar is setting white.
Here is the screen shot for drawer
Sorry i had to change some colors as i can't show the whole design.
Go to the Storyboard. Select the View and in the Attributes Inspector change the Background Color to Light Gray. Build and Run the Project. The default style of the status bar is dark content.
Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.
If you want to change a status bar text color across your app, a theme is always the right choice for this kind of task. To do that, set brightness property in AppBarTheme to either Brightness. dark or Brightness.
As i came to understand the problem because of sidemenu to overcome this issue we have one library very easy to customize
To set or to change root, left or right view controllers or views, call:
sideMenuController.rootViewController = rootViewController
sideMenuController.leftViewController = leftViewController
sideMenuController.rightViewController = rightViewController
sideMenuController.rootView = rootView
sideMenuController.leftView = leftView
sideMenuController.rightView = rightView
Hope this will help you
Maybe because your SideView
has a white background. Try changing that in the storyboard
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With