Updated 4 July 2023
Some time we need to popup a controller on click of UIButton event not to cover all screen just cover some part of screen so we can show some message or perform some action on controller .
For this we need to follow some steps:
1: Take a Two UIViewController like that:
2: Here is “POP” is UIbutton , connect firstView Controller to another by Model Popover .
a: Select Button
b: go To “Connection Inspector”
c: In Triggered Section – select the action and connect to 2nd controller as “present as PopOver”
3: Now Its time to write the code in 1st viewcontroller.
a: Add the “UIPopoverPresentationControllerDelegate” in 1st UIViewcontroller class.
b: write their delegate method in 1st class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { return .none } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // All popover segues should be popovers even on iPhone. if let popoverController = segue.destination.popoverPresentationController, let button = sender as? UIButton { popoverController.delegate = self popoverController.sourceRect = button.bounds } guard let identifier = segue.identifier, let segueIdentifer = SegueIdentifier(rawValue: identifier) else { return } if segueIdentifer == .showObjects, let objectsViewController = segue.destination as? POpUpViewController { } } |
It will look like as :
Here I have taken in 2nd Viewcontroller UItableview so you can can take any thing depends on your requirement.
You can also set the size of UITableView like that:
1 2 3 |
override func viewWillLayoutSubviews() { preferredContentSize = CGSize(width: 300, height: tableView.contentSize.height) } |
Here
I have taken custom width & Height if TableView .
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.