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

add popMenuContentInset #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions PopMenu/Classes/PopMenuAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ final public class PopMenuAppearance: NSObject {

/// The presentation style
public var popMenuPresentationStyle: PopMenuPresentationStyle = .cover()

/// ContentInset of menu, includes left right top bottom
public var popMenuContentInset: UIEdgeInsets = .zero

}

Expand Down
25 changes: 12 additions & 13 deletions PopMenu/View Controller & Views/PopMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ extension PopMenuViewController {
height = CGFloat(actions.count) * appearance.popMenuActionHeight
}

let size = CGSize(width: calculateContentWidth(), height: height)
let size = CGSize(width: calculateContentWidth() + appearance.popMenuContentInset.left + appearance.popMenuContentInset.right, height: height + appearance.popMenuContentInset.top + appearance.popMenuContentInset.bottom)
let origin = calculateContentOrigin(with: size)

return CGRect(origin: origin, size: size)
Expand Down Expand Up @@ -463,7 +463,7 @@ extension PopMenuViewController {

actionsView.addArrangedSubview(action.view)
}

// Check add scroll view or not
if actions.count >= (appearance.popMenuActionCountForScrollable) {
// Scrollable actions
Expand All @@ -478,29 +478,28 @@ extension PopMenuViewController {
contentView.addSubview(scrollView)

NSLayoutConstraint.activate([
scrollView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
scrollView.topAnchor.constraint(equalTo: contentView.topAnchor),
scrollView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
scrollView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: appearance.popMenuContentInset.left),
scrollView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: appearance.popMenuContentInset.top),
scrollView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -appearance.popMenuContentInset.right),
scrollView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -appearance.popMenuContentInset.bottom)
])

NSLayoutConstraint.activate([
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: appearance.popMenuContentInset.left),
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -appearance.popMenuContentInset.right),
actionsView.topAnchor.constraint(equalTo: scrollView.topAnchor),
actionsView.heightAnchor.constraint(equalToConstant: scrollView.contentSize.height)
])
} else {
// Not scrollable
actionsView.addGestureRecognizer(panGestureForMenu)

contentView.addSubview(actionsView)

NSLayoutConstraint.activate([
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor),
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor),
actionsView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 4),
actionsView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -4)
actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: appearance.popMenuContentInset.left),
actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor, constant: -appearance.popMenuContentInset.right),
actionsView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: appearance.popMenuContentInset.top),
actionsView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -appearance.popMenuContentInset.bottom)
])
}
}
Expand Down