I am trying to set the background and trasparecy for UINavigation bar in code, in the ViewWillAppear func. however it doesn't seem to be working.
self.navigationController!.navigationBar.translucent = false
self.navigationController!.navigationBar.backgroundColor = UIColor.blackColor()
the view controller is load via the storyboard id
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(storyboardId)
vc.title = storyboardId
let navigationController = UINavigationController(rootViewController: vc)
self.presentViewController(navigationController, animated: false, completion: nil)
i have tried setting it there too, doesn't seem to be working.
additionally i tried with UINavigationBar.appearance() to set the properties, this too doesn't work.
You can try with this:
self.navigationController?.barTintColor = UIColor.blackColor()
Related
After sucessful signin i am opening Tabbar with follwing code
let mainView = UIStoryboard(name:"Main", bundle: nil)
let tabbar = mainView.instantiateViewController(withIdentifier: "Tabbar") as? Tabbar
tabbar?.modalPresentationStyle = .fullScreen
self.present(tabbar!, animated: true, completion: nil)
Its open Tabbar with first index selected but first ViewController also cover the save area ...
and switching between the TabbarItems make it work fine ...
I am not able to understand why this happening only in one ViewController on first time open ... and how to tackle that.
Also tried following code but did't work ...
self.edgesForExtendedLayout = []
Its not the proper solution its a kind of hack ... I told in Question that its get automatically fixed after switching between TabbarItems ... so i just added Two lines right after opening Tabbar VC.
tabbar?.selectedIndex = 1
tabbar?.selectedIndex = 0
And know the complete code seems like this.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let mainView = UIStoryboard(name:"Main", bundle: nil)
let tabbar = mainView.instantiateViewController(withIdentifier: "Tabbar") as? Tabbar
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
appDelegate.window!.rootViewController = tabbar
appDelegate.window!.makeKeyAndVisible()
tabbar?.modalPresentationStyle = .fullScreen
self.present(tabbar!, animated: true, completion: nil)
tabbar?.selectedIndex = 1
tabbar?.selectedIndex = 0
I would like to resent an viewcontroller as modal view in size .formSheet. The background color should not be grey transparent, it should be an blur effect.
How I cloud change the background color of view behind modal.
let storyboard = UIStoryboard(name: "DetailViewController", bundle: nil)
if let modalViewController = storyboard.instantiateInitialViewController() as? DetailViewController {
self.definesPresentationContext = true
self.providesPresentationContextTransitionStyle = true
modalViewController.item = item
modalViewController.modalPresentationStyle = .formSheet
modalViewController.modalPresentationCapturesStatusBarAppearance = true
self.present(modalViewController, animated: true, completion: nil)
}
From the viewWillAppear(:) method of your modalViewController, you can access the self.presentationController?.containerView property. You can either change the background color or even add a blur effect view if you want.
I have UITabBarController having 4 tabs. inside the first tab's ViewController i presented Popup using popUpVC.modalPresentationStyle = .overCurrentContext
so i got this(thats perfect as i want):
but now when i switch to secondTab Dollor_Icon, and then immediately come back to firstTab... i get the blackBG instead of transparent BG.
like this:
my code of modal presentation:
let popUpVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PopUp")
popUpVC.modalPresentationStyle = .overCurrentContext
self.present(popUpVC, animated: true)
Hope to get rid of that black background and why is this happening?
Thanks!
Add this to your firstTabViewController ViewDidLoad() method:
definesPresentationContext = true
Hope, your problem being fixed.
For more details on definesPresentationContext see https://developer.apple.com/documentation/uikit/uiviewcontroller/1621456-definespresentationcontext'
I tried same code mention in gist : https://gist.github.com/barbietunnie/e5547f35180436ac102cac52a15f8ca3
func showModal() {
let modalViewController = ModalViewController()
modalViewController.modalPresentationStyle = .OverCurrentContext
presentViewController(modalViewController, animated: true, completion: nil)
}
class ModalViewController: UIViewController {
override func viewDidLoad() {
view.backgroundColor = UIColor.clearColor()
view.opaque = false
}
}
Its working fine but in case of tab bar the content is getting beyond tab bar, How can we make content visible upper/front of tab bar?
It worked via vc.modalPresentationStyle = .overFullScreen
I hope it will work for you,
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "ModalViewController") as! ModalViewController
controller.modalPresentationStyle = .overCurrentContext
Thank You.
In some cases I want my app to present a different view controller than the one that normally loads (in this case AltView rather than MainView), but I can't figure out how to do it. I tried like this:
let storyboard = UIStoryboard.init(name: "Alt", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("AltView")
let mainStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
let rootVC = mainStoryboard.instantiateViewControllerWithIdentifier("MainView")
self.window!.rootViewController = rootVC
window!.makeKeyAndVisible()
self.window!.rootViewController?.presentViewController(nav, animated: true, completion: nil)
But nothing happens, the screen is just blank, no errors or warnings are being reported.
EDIT: AltView is an UINavigationController with an embedded UIViewController. The viewDidLoad() method of AltView's embedded view controller is being run, but its viewWillAppear() method is not.
What am I doing wrong?
Just set the window controller like this
let mainStoryboard = UIStoryboard.init(name: "Main", bundle: nil)
let nav = storyboard.instantiateViewControllerWithIdentifier("AltView")
self.window!.rootViewController = nav
If u want to change the controller change the window rootviewcontroller again with same code just change the identifier to the one that you want of the controller and you don't need this statement `self.window!.rootViewController?.presentViewController(nav, animated: true, completion: nil)
If you face any issues let me know