0

How can I recreate this type of menu in Swift using UIkit? Is it possible to play the same animation as well?

https://i.sstatic.net/h5kXC.jpg

asked Aug 27, 2020 at 8:30
2

2 Answers 2

0

Try setting button.showsMenuAsPrimaryAction = true to your button. And don't forget to assign menu property.

answered Oct 18, 2024 at 17:46
Sign up to request clarification or add additional context in comments.

Comments

-1

Okay, enjoy

class ViewController: UIViewController {
 let filterButton = UIButton()
 override func viewDidLoad() {
 super.viewDidLoad()
 
 filterButton.setImage(UIImage(systemName: "ellipsis.circle"), for: .normal)
 filterButton.tintColor = .blue
 filterButton.addTarget(self, action: #selector(showFilters), for: .touchUpInside)
 filterButton.translatesAutoresizingMaskIntoConstraints = false
 view.addSubview(filterButton)
 NSLayoutConstraint.activate([
 filterButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
 filterButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
 ])
 }
 @objc func showFilters() {
 let alertController = UIAlertController( title: nil, message: nil, preferredStyle: .actionSheet)
 let scanButton = UIAlertAction(title: "Scan document", style: .default) { _ in
 print(" 1 selected")
 }
 let connectButton = UIAlertAction(title: "Connect to Server", style: .default) { _ in
 print(" 2 selected")
 }
 let editButton = UIAlertAction(title: "Edit", style: .default) { _ in
 print(" 3 selected")
 }
 let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
 alertController.addAction(scanButton)
 alertController.addAction(connectButton)
 alertController.addAction(editButton)
 alertController.addAction(cancelAction)
 alertController.popoverPresentationController?.sourceView = filterButton
 alertController.popoverPresentationController?.sourceRect = filterButton.bounds
 alertController.popoverPresentationController?.permittedArrowDirections = .up
 present(alertController, animated: true, completion: nil)
 }
}
answered Apr 17, 2024 at 13:26

1 Comment

Hello, and welcome to Stack Overflow! Please add some explanation to your answer as what the code does and how it fixes the problem.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.