I'm trying to create a popover that only intends takes up a small part of a screen. I would like to open the popover from a button in the navigation bar. I've tried searching it but I was only able to find outdated posts which didn't get me any further.
I hope somebody knows a way or can hopefully point me in a direction.
Something like this is what I am trying to achieve:
Solution:
Create a new ViewController (with a modal, cross dissolve segue to it).
Make the view non-opaque and make the background color of the view clear or 'darken' the background, explained a few lines under here. After that add any view (UIView, UIStackView, UILabel, UIButton, etc) on top and you can make it however you like! Code:
Swift 5:
class PopoverViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.isOpaque = false
self.view.backgroundColor = .clear
}
}
For 'darkening' the background set the view's background color to black with an alpha between 0.4 and 0.6 depending on how much you'd like the background to darken. Example:
Swift 5:
class PopoverViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.isOpaque = false
self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
}
}
One of the best way to achieve this by presenting a new view controller. Things to keep in mind in order to achieve the best user experience.