Hỏi về cách tạo dropdown menu trong iOS

có ai bik cách làm menu sổ xuống trong ios k ạ. e tìm trên mạng thì hầu như xài theo kiểu menu trượt từ trái hay phải sang mà k xổ ra tại màn hình chính lun ai bik thông não cho e với xin cảm ơn nhìu ạ

Cho mình minh hoạ đi bạn, có video đầy đủ animation càng tốt nữa. Như thế mình mới có thể hướng dẫn nên dùng transition nào, và animate như thế nào. Vì ít khi nào mình build app xài dropdown mặc định của Apple, đa số phải custom lại.

Nếu bạn thích mặc định của Apple thì dùng kiểu popover presentation.

let presentingController = UIViewController()
let presentedController = UIViewController()

presentedController.modalPresentationStyle = .popover
presentedController.preferredContentSize = CGSize(width: bounds.width / 2, height: bounds.height / 2)

presentedController.popoverPresentationController?.sourceView = selectedView
presentedController.popoverPresentationController?.permittedArrowDirections = .up

presentingController.present(presentedController, animated: true, completion: nil)
3 Likes

CustomView hoặc sài Libs. Nếu thực sự muốn vẽ theo ý của bạn .

1 Like

kiểu như thế này nè bấm váo button cái nó sổ xuống á

thanks bác để e thử xem dc hem

Menu đó là popover mặc định.
View chứa Danh sách United States, Canada,… là 1 controller, gọi là presentedController. presentedController chứa UITableView.

Hoặc có thể xài lib:
Objective-C: https://github.com/liufengting/FTPopOverMenu
Swift: https://github.com/liufengting/FTPopOverMenu_Swift

1 Like

thanks bác nhìu đúng cái bữa h đang tìm

vậy check solution cho comment mình đi :yum: (gần nút reply) sống ảo tí

1 Like

là cắm cờ hỡ bác àh mà cho e hỏi xíu sao e chỉnh cái bar-button e mún cài làm hình ảnh áh mà sao nó ra thế này lun

alo bác ơi cho em hỏi cái việc tạo hình cho button với

Phần tạo BarButtonItem có thể tạo bằng code hoặc Storyboard:
Thay ảnh bạn muốn chèn vào “your-image”.

Trong hàm rightBarButtonItemTapped(_ barButtonItem: UIBarButtonItem) present controller theo dạng popover (hoặc theo hướng dẫn của lib)

let controller = UIViewController()

let buttonItem = UIBarButtonItem(
    image: UIImage(named: "your-image"),
    style: .plain,
    target: controller,
    action: #selector(rightBarButtonItemTapped(_:))
)

let navigationItem = controller.navigationItem
navigationItem.rightBarButtonItem = buttonItem

Nút solution giống như checkbox :slight_smile: , còn nút lá cờ là nút spam :frowning:

hờ hờ e hỉu sao thay hình vô button gặp lỗi rùi quên mất cái vụ PNG :smile:

DropDown thì mình đang dùng cái này rất tiện:

1 Like
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?