Skip to content

Commit

Permalink
- fixed rotation resizing for segmented control use case
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Fahl committed Jan 20, 2015
1 parent 83e3f05 commit 9e67b28
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
26 changes: 22 additions & 4 deletions Classes/CAPSPageMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ import UIKit
class MenuItemView: UIView {

var titleLabel : UILabel?
var menuItemSeparator : UIView?

func setUpMenuItemView(menuItemWidth: CGFloat, menuScrollViewHeight: CGFloat, indicatorHeight: CGFloat) {
titleLabel = UILabel(frame: CGRectMake(0.0, 0.0, menuItemWidth, menuScrollViewHeight - indicatorHeight))

menuItemSeparator = UIView(frame: CGRectMake(menuItemWidth, floor(menuScrollViewHeight * 0.2), 0.5, menuScrollViewHeight - (2.0 * floor(menuScrollViewHeight * 0.2))))
menuItemSeparator!.backgroundColor = UIColor.lightGrayColor()
menuItemSeparator!.hidden = true
self.addSubview(menuItemSeparator!)

self.addSubview(titleLabel!)
}

Expand Down Expand Up @@ -258,10 +264,7 @@ class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecognizerD
// Add separator between menu items when using as segmented control
if useMenuLikeSegmentedControl {
if Int(index) < controllerArray.count - 1 {
var menuItemSeparator : UIView = UIView(frame: CGRectMake(menuItemView.frame.width, floor(menuHeight * 0.2), 0.5, menuHeight - (2.0 * floor(menuHeight * 0.2))))
println("\(menuItemSeparator.frame.height), \(menuItemSeparator.frame.origin.y)")
menuItemSeparator.backgroundColor = UIColor.lightGrayColor()
menuItemView.addSubview(menuItemSeparator)
menuItemView.menuItemSeparator!.hidden = false
}
}

Expand Down Expand Up @@ -611,6 +614,21 @@ class CAPSPageMenu: UIViewController, UIScrollViewDelegate, UIGestureRecognizerD
// Configure controller scroll view content size
controllerScrollView.contentSize = CGSizeMake(self.view.frame.width * CGFloat(controllerArray.count), self.view.frame.height - menuHeight)

//Resize menu items if using as segmented control
if useMenuLikeSegmentedControl {
menuScrollView.contentSize = CGSizeMake(self.view.frame.width, menuHeight)

var index : Int = 0

for item : MenuItemView in menuItems as [MenuItemView] {
item.frame = CGRectMake(self.view.frame.width / CGFloat(controllerArray.count) * CGFloat(index), 0.0, self.view.frame.width / CGFloat(controllerArray.count), menuHeight)
item.titleLabel!.frame = CGRectMake(0.0, 0.0, self.view.frame.width / CGFloat(controllerArray.count), menuHeight)
item.menuItemSeparator!.frame = CGRectMake(item.frame.width, item.menuItemSeparator!.frame.origin.y, item.menuItemSeparator!.frame.width, item.menuItemSeparator!.frame.height)

index++
}
}

for view : UIView in controllerScrollView.subviews as [UIView] {
view.frame = CGRectMake(self.view.frame.width * CGFloat(currentPageIndex), menuHeight, controllerScrollView.frame.width, self.view.frame.height - menuHeight)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="600" height="536"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="nnR-NB-3Xj">
Expand All @@ -36,7 +36,7 @@
<scene sceneID="XTP-9k-OxM">
<objects>
<navigationController id="EUK-xa-gOe" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="wJh-BS-t49">
<navigationBar key="navigationBar" contentMode="scaleToFill" translucent="NO" id="wJh-BS-t49">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<color key="barTintColor" red="0.0" green="0.25290398848684209" blue="0.48018606085526316" alpha="1" colorSpace="calibratedRGB"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ViewController: UIViewController {
pageMenu = CAPSPageMenu(viewControllers: controllerArray)

// Set frame for scroll menu (set y origin to height of navbar if navbar is used and is transparent)
pageMenu!.view.frame = CGRectMake(0.0, 64.0, self.view.frame.width, self.view.frame.height - 64.0)
pageMenu!.view.frame = CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height)

// Customize menu (Optional)
pageMenu!.scrollMenuBackgroundColor = UIColor.whiteColor()
Expand Down

0 comments on commit 9e67b28

Please sign in to comment.