From 3ba417d5056947eb0dec19c1e3305edfe63aa958 Mon Sep 17 00:00:00 2001 From: Cali Castle Date: Mon, 3 Sep 2018 16:15:35 -0700 Subject: [PATCH] Fix #10 --- .../Helper/PopMenuExamples.swift | 3 +- PopMenu/Classes/PopMenuAppearance.swift | 6 +++ PopMenu/Info.plist | 2 +- .../PopMenuViewController.swift | 52 +++++++++++++++---- README.md | 12 ++++- 5 files changed, 61 insertions(+), 14 deletions(-) diff --git a/Example/Example/View Controllers/Helper/PopMenuExamples.swift b/Example/Example/View Controllers/Helper/PopMenuExamples.swift index 2138458..8a1229b 100644 --- a/Example/Example/View Controllers/Helper/PopMenuExamples.swift +++ b/Example/Example/View Controllers/Helper/PopMenuExamples.swift @@ -196,7 +196,8 @@ final class PopMenuExamples { PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)), PopMenuDefaultAction(title: "Save to List", image: #imageLiteral(resourceName: "Plus"), color: #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)), PopMenuDefaultAction(title: "Favorite", image: #imageLiteral(resourceName: "Heart"), color: #colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1)), - PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)) + PopMenuDefaultAction(title: "Add to Cart", image: #imageLiteral(resourceName: "Cart_Add"), color: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1)), + PopMenuDefaultAction(title: "Last Action", image: #imageLiteral(resourceName: "Download"), color: #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)) ] let popMenu = PopMenuViewController(actions: actions) diff --git a/PopMenu/Classes/PopMenuAppearance.swift b/PopMenu/Classes/PopMenuAppearance.swift index ea87479..e66507c 100644 --- a/PopMenu/Classes/PopMenuAppearance.swift +++ b/PopMenu/Classes/PopMenuAppearance.swift @@ -35,6 +35,12 @@ final public class PopMenuAppearance: NSObject { /// How many actions are the breakpoint to trigger scrollable. public var popMenuActionCountForScrollable: UInt = 6 + + /// The scroll indicator style when the actions are scrollable. + public var popMenuScrollIndicatorStyle: UIScrollView.IndicatorStyle = .white + + /// Hide the scroll indicator or not when the actions are scrollable. + public var popMenuScrollIndicatorHidden = false /// The separator style for each action. public var popMenuItemSeparator: PopMenuActionSeparator = .none() diff --git a/PopMenu/Info.plist b/PopMenu/Info.plist index 0202029..3d809ff 100644 --- a/PopMenu/Info.plist +++ b/PopMenu/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.1.2 + 2.1.0 CFBundleVersion $(CURRENT_PROJECT_VERSION) NSPrincipalClass diff --git a/PopMenu/View Controller & Views/PopMenuViewController.swift b/PopMenu/View Controller & Views/PopMenuViewController.swift index 1e6510e..118dea9 100644 --- a/PopMenu/View Controller & Views/PopMenuViewController.swift +++ b/PopMenu/View Controller & Views/PopMenuViewController.swift @@ -323,9 +323,10 @@ extension PopMenuViewController { fileprivate func calculateContentFittingFrame() -> CGRect { var height: CGFloat - if actions.count >= 6 { + if actions.count >= appearance.popMenuActionCountForScrollable { // Make scroll view height = CGFloat(appearance.popMenuActionCountForScrollable) * appearance.popMenuActionHeight + height -= 20 } else { height = CGFloat(actions.count) * appearance.popMenuActionHeight } @@ -424,8 +425,6 @@ extension PopMenuViewController { /// Setup actions view. fileprivate func configureActionsView() { - actionsView.addGestureRecognizer(panGestureForMenu) - actionsView.translatesAutoresizingMaskIntoConstraints = false actionsView.axis = .vertical actionsView.alignment = .fill @@ -451,14 +450,45 @@ extension PopMenuViewController { actionsView.addArrangedSubview(action.view) } - 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) - ]) + // Check add scroll view or not + if actions.count >= (appearance.popMenuActionCountForScrollable) { + // Scrollable actions + let scrollView = UIScrollView() + scrollView.translatesAutoresizingMaskIntoConstraints = false + scrollView.showsHorizontalScrollIndicator = false + scrollView.showsVerticalScrollIndicator = !appearance.popMenuScrollIndicatorHidden + scrollView.indicatorStyle = appearance.popMenuScrollIndicatorStyle + scrollView.contentSize.height = appearance.popMenuActionHeight * CGFloat(actions.count) + + scrollView.addSubview(actionsView) + 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) + ]) + + NSLayoutConstraint.activate([ + actionsView.leftAnchor.constraint(equalTo: contentView.leftAnchor), + actionsView.rightAnchor.constraint(equalTo: contentView.rightAnchor), + 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) + ]) + } } /// Add separator view for the given action view. diff --git a/README.md b/README.md index 5bf98d5..3194e05 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,7 @@ You can, however, choose either way to have the same result, whichever works bes [Basic Usage - Using Manager](#using-manager) -[Basic Usage - Using Controller](#using-controller) +[Basic Usage - Using Controller (Recommended)](#using-controller) ------- @@ -493,7 +493,17 @@ To set the action item image sizing: let action = PopMenuDefaultAction(title: "Some Title", image: UIImage(named: "blah"), color: .gray) action.iconWidthHeight = 45 ``` +Scrollable when actions are more than 6 or custom +--------- + +To set the scrolling properties: +```swift +// The manual way +menu.appearance.popMenuActionCountForScrollable = 10 // default 6 +menu.appearance.popMenuScrollIndicatorHidden = true // default false +menu.appearance.popMenuScrollIndicatorStyle = .black // default .white +``` Status Bar Style // Default: automatic detection based on background color ---------