Skip to content

Commit

Permalink
Fix #10
Browse files Browse the repository at this point in the history
  • Loading branch information
CaliCastle committed Sep 3, 2018
1 parent a6fb178 commit 3ba417d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions PopMenu/Classes/PopMenuAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion PopMenu/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.2</string>
<string>2.1.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
52 changes: 41 additions & 11 deletions PopMenu/View Controller & Views/PopMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -424,8 +425,6 @@ extension PopMenuViewController {

/// Setup actions view.
fileprivate func configureActionsView() {
actionsView.addGestureRecognizer(panGestureForMenu)

actionsView.translatesAutoresizingMaskIntoConstraints = false
actionsView.axis = .vertical
actionsView.alignment = .fill
Expand All @@ -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.
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

-------

Expand Down Expand Up @@ -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
---------

Expand Down

0 comments on commit 3ba417d

Please sign in to comment.