Skip to content

Commit

Permalink
Merge pull request #2 from alexbredy/master
Browse files Browse the repository at this point in the history
Allows to offset the selection indicator by an arbitrary amount of points
  • Loading branch information
orazz authored Oct 13, 2016
2 parents 4c4052e + 54c9b23 commit 4ec4be6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Classes/CAPSPageMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class MenuItemView: UIView {
}

public enum CAPSPageMenuOption {
case selectionIndicatorBottomOffset(CGFloat)
case selectionIndicatorHeight(CGFloat)
case menuItemSeparatorWidth(CGFloat)
case scrollMenuBackgroundColor(UIColor)
Expand Down Expand Up @@ -104,6 +105,7 @@ open class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecogn
open var menuHeight : CGFloat = 34.0
open var menuMargin : CGFloat = 15.0
open var menuItemWidth : CGFloat = 111.0
open var selectionIndicatorBottomOffset : CGFloat = 0.0
open var selectionIndicatorHeight : CGFloat = 3.0
var totalMenuItemWidthIfDifferentWidths : CGFloat = 0.0
open var scrollAnimationDurationOnMenuItemTap : Int = 500 // Millisecons
Expand Down Expand Up @@ -190,6 +192,8 @@ open class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecogn
if let options = pageMenuOptions {
for option in options {
switch (option) {
case let .selectionIndicatorBottomOffset(value):
selectionIndicatorBottomOffset = value
case let .selectionIndicatorHeight(value):
selectionIndicatorHeight = value
case let .menuItemSeparatorWidth(value):
Expand Down Expand Up @@ -496,14 +500,14 @@ open class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecogn
var selectionIndicatorFrame : CGRect = CGRect()

if useMenuLikeSegmentedControl {
selectionIndicatorFrame = CGRect(x: 0.0, y: menuHeight - selectionIndicatorHeight, width: self.view.frame.width / CGFloat(controllerArray.count), height: selectionIndicatorHeight)
selectionIndicatorFrame = CGRect(x: 0.0, y: menuHeight - selectionIndicatorHeight - selectionIndicatorBottomOffset, width: self.view.frame.width / CGFloat(controllerArray.count), height: selectionIndicatorHeight)
} else if menuItemWidthBasedOnTitleTextWidth {
selectionIndicatorFrame = CGRect(x: menuMargin, y: menuHeight - selectionIndicatorHeight, width: menuItemWidths[0], height: selectionIndicatorHeight)
selectionIndicatorFrame = CGRect(x: menuMargin, y: menuHeight - selectionIndicatorHeight - selectionIndicatorBottomOffset, width: menuItemWidths[0], height: selectionIndicatorHeight)
} else {
if centerMenuItems {
selectionIndicatorFrame = CGRect(x: startingMenuMargin + menuMargin, y: menuHeight - selectionIndicatorHeight, width: menuItemWidth, height: selectionIndicatorHeight)
selectionIndicatorFrame = CGRect(x: startingMenuMargin + menuMargin, y: menuHeight - selectionIndicatorHeight - selectionIndicatorBottomOffset, width: menuItemWidth, height: selectionIndicatorHeight)
} else {
selectionIndicatorFrame = CGRect(x: menuMargin, y: menuHeight - selectionIndicatorHeight, width: menuItemWidth, height: selectionIndicatorHeight)
selectionIndicatorFrame = CGRect(x: menuMargin, y: menuHeight - selectionIndicatorHeight - selectionIndicatorBottomOffset, width: menuItemWidth, height: selectionIndicatorHeight)
}
}

Expand Down

0 comments on commit 4ec4be6

Please sign in to comment.