Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

홈 화면의 책 드랍다운 버튼 클릭 시 UIMenu 로직 구현 #114

Merged
merged 9 commits into from
Dec 2, 2024

Conversation

Kyxxn
Copy link
Member

@Kyxxn Kyxxn commented Dec 1, 2024

#️⃣ 연관된 이슈


⏰ 작업 시간

예상 시간 실제 걸린 시간
1 2

📝 작업 내용

  • UIButton에 있는 menu 프로퍼티를 통해 메뉴를 구현했습니다.
  • 아직 BookCreation 뷰모델이 완벽하지 않아서 '책커버 수정'은 안 했고,
    '책커버 삭제'만 구현해뒀습니다

📸 스크린샷

DropDown Menu UI 구현

📚 리뷰노트

UIButton의 menu

UIButton에는 Menu라는 프로퍼티가 있다.

iOS 14버전 이상부터 쓸 수 있음 !!

/// An optional menu for the button to display. The button will automatically enable or disable its contextMenuInteraction when a non-nil or nil menu is set. Defaults to nil.
@available(iOS 14.0, *)
@NSCopying open var menu: UIMenu?
dropDownButton.menu = UIMenu(
    title: "",
    children: [
        UIAction(
            title: "책 커버 수정",
            image: UIImage(systemName: "pencil"),
            handler: { _ in dropDownButtonEditAction() }
        ),
        UIAction(
            title: "책 커버 삭제",
            image: UIImage(systemName: "trash"),
            attributes: .destructive,
            handler: { _ in dropDownButtonDeleteAction() }
        )
    ]
)

근데 기본적으로 버튼에 들어가는 menu는 꾹 눌러야 메뉴가 뜬다.

그러면 나처럼 클릭했을 때 바로 menu가 보이게 하려면 어떻게 할까 ??

처음에 addAction이나 addTarget에 넣어야 하나 했지만, 이런게 있었다

얘를 true로 설정해주면 버튼을 꾹 누르지 않고도, 클릭 한 번으로 메뉴를 나오게 할 수 있다 !!

/// If the contextMenuInteraction is the primary action of the control, invoked on touch-down. NO by default.
@available(iOS 14.0, *)
open var showsMenuAsPrimaryAction: Bool

수정된 나의 코드

dropDownButton.showsMenuAsPrimaryAction = true
dropDownButton.menu = UIMenu(
    title: "",
    children: [
        UIAction(
            title: "책 커버 수정",
            image: UIImage(systemName: "pencil"),
            handler: { _ in dropDownButtonEditAction() }
        ),
        UIAction(
            title: "책 커버 삭제",
            image: UIImage(systemName: "trash"),
            attributes: .destructive,
            handler: { _ in dropDownButtonDeleteAction() }
        )
    ]
)

@Kyxxn Kyxxn added the ✨ Feature 기능 관련 작업 label Dec 1, 2024
@Kyxxn Kyxxn added this to the 0.5 milestone Dec 1, 2024
@Kyxxn Kyxxn self-assigned this Dec 1, 2024
@Kyxxn Kyxxn linked an issue Dec 1, 2024 that may be closed by this pull request
Copy link
Collaborator

@iceHood iceHood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 좋아요! 짱짱맨..

Copy link
Collaborator

@k2645 k2645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ~~ 👍

@Kyxxn Kyxxn merged commit a505387 into develop Dec 2, 2024
2 checks passed
@Kyxxn Kyxxn deleted the feature/edit-bookcover-in-home branch December 2, 2024 02:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature 기능 관련 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

책커버 드랍다운 버튼
3 participants