I have an options button (that 3 vertical dotted button) on top of the view controller. When I click that button, A list view should appear like in many other apps like WhatsApp... I really don't know how to position it always near to the button programmatically.
Asked
Active
Viewed 314 times
-1
-
You can add a custom view when clicking on that button – IOS Singh May 20 '19 at 08:52
2 Answers
0
Placing at the left-bottom of an existing view is quite easier:
func placeSubView(existingView: UIView)
{
let desiredWidth = CGFloat(50.0)
let desiredHeight = CGFloat(35.0)
let (x, y) = (existingView.frame.origin.x - desiredWidth, existingView.frame.origin.y + existingView.frame.size.height)
let desiredView = UIView(frame: CGRect(x: x, y: y, width: desiredWidth, height: desiredHeight))
existingView.superview?.addSubview(desiredView)
}
UPDATE:
In case you are looking for popupo menu like view, you should search about UIPopoverPresentationController.
Something like this.

Nirav Bhatt
- 6,940
- 5
- 45
- 89
0
Use this method and make PopoverViewController a table view controller if you want a list.
@IBAction func displayPopover(_ sender: UIBarButtonItem) {
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PopoverViewController")
vc.modalPresentationStyle = .popover
let popover: UIPopoverPresentationController = vc.popoverPresentationController!
popover.barButtonItem = sender
present(vc, animated: true, completion:nil)
}

Saurabh Singh
- 247
- 1
- 6