Skip to content

Commit

Permalink
Support Storyboard and code at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouhao27 committed Mar 17, 2017
1 parent c30c0f4 commit 90bee6b
Show file tree
Hide file tree
Showing 11 changed files with 220 additions and 37 deletions.
8 changes: 8 additions & 0 deletions Example/WOWCardStackView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
386177201E7BBF68006F4F5E /* DetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3861771F1E7BBF68006F4F5E /* DetailsViewController.swift */; };
386177221E7BC2DD006F4F5E /* placeholder.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 386177211E7BC2DD006F4F5E /* placeholder.jpg */; };
38F5CE7A1E7B881700A7FCA0 /* MyCard.xib in Resources */ = {isa = PBXBuildFile; fileRef = 38F5CE791E7B881700A7FCA0 /* MyCard.xib */; };
38F5CE7C1E7B8A1600A7FCA0 /* MyCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38F5CE7B1E7B8A1600A7FCA0 /* MyCard.swift */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
Expand Down Expand Up @@ -34,6 +36,8 @@
0C60282BA410B7570717C313 /* Pods-WOWCardStackView_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WOWCardStackView_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WOWCardStackView_Tests/Pods-WOWCardStackView_Tests.debug.xcconfig"; sourceTree = "<group>"; };
22BB6C624B682C38943B9C46 /* Pods_WOWCardStackView_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WOWCardStackView_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
30091B23E72D1AB9E49886BF /* Pods-WOWCardStackView_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WOWCardStackView_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-WOWCardStackView_Example/Pods-WOWCardStackView_Example.release.xcconfig"; sourceTree = "<group>"; };
3861771F1E7BBF68006F4F5E /* DetailsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DetailsViewController.swift; sourceTree = "<group>"; };
386177211E7BC2DD006F4F5E /* placeholder.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = placeholder.jpg; sourceTree = "<group>"; };
38F5CE791E7B881700A7FCA0 /* MyCard.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MyCard.xib; sourceTree = "<group>"; };
38F5CE7B1E7B8A1600A7FCA0 /* MyCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyCard.swift; sourceTree = "<group>"; };
5D57B462CADD95BAA877731F /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
Expand Down Expand Up @@ -108,6 +112,7 @@
607FACD21AFB9204008FA782 /* Example for WOWCardStackView */ = {
isa = PBXGroup;
children = (
386177211E7BC2DD006F4F5E /* placeholder.jpg */,
38F5CE7B1E7B8A1600A7FCA0 /* MyCard.swift */,
38F5CE791E7B881700A7FCA0 /* MyCard.xib */,
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
Expand All @@ -116,6 +121,7 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */,
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
3861771F1E7BBF68006F4F5E /* DetailsViewController.swift */,
);
name = "Example for WOWCardStackView";
path = WOWCardStackView;
Expand Down Expand Up @@ -257,6 +263,7 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
386177221E7BC2DD006F4F5E /* placeholder.jpg in Resources */,
38F5CE7A1E7B881700A7FCA0 /* MyCard.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -371,6 +378,7 @@
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
38F5CE7C1E7B8A1600A7FCA0 /* MyCard.swift in Sources */,
386177201E7BBF68006F4F5E /* DetailsViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
69 changes: 66 additions & 3 deletions Example/WOWCardStackView/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="op4-yf-pKr">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -23,10 +23,10 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dDK-WX-GHa" customClass="CardStackView" customModule="WOWCardStackView">
<rect key="frame" x="16" y="46" width="343" height="240"/>
<rect key="frame" x="16" y="90" width="343" height="160"/>
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
<constraints>
<constraint firstAttribute="height" constant="240" id="fAk-FB-6sw"/>
<constraint firstAttribute="height" constant="160" id="fAk-FB-6sw"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="offsetY">
Expand All @@ -45,12 +45,75 @@
<constraint firstItem="dDK-WX-GHa" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="26" id="qEt-xJ-I2T"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="qIW-yo-dKi"/>
<connections>
<outlet property="cardStackView" destination="dDK-WX-GHa" id="JNs-fP-TUY"/>
<segue destination="mHi-HE-Qju" kind="show" identifier="ShowDetails" id="gPK-Ia-wKS"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1076" y="138.98050974512745"/>
</scene>
<!--Details View Controller-->
<scene sceneID="TFS-vb-h7A">
<objects>
<viewController storyboardIdentifier="DetailsViewController" id="mHi-HE-Qju" customClass="DetailsViewController" customModule="WOWCardStackView_Example" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Byb-Zc-DtF"/>
<viewControllerLayoutGuide type="bottom" id="Kf6-Tq-1eM"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="NM4-L1-Iov">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="CL8-c8-W96" customClass="CardStackView" customModule="WOWCardStackView">
<rect key="frame" x="16" y="84" width="343" height="320"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="height" constant="320" id="T33-cE-T53"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="offsetY">
<real key="value" value="10"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="scaleFactor">
<real key="value" value="0.98999999999999999"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="CL8-c8-W96" firstAttribute="top" secondItem="Byb-Zc-DtF" secondAttribute="bottom" constant="20" id="LNe-1e-FDN"/>
<constraint firstItem="CL8-c8-W96" firstAttribute="leading" secondItem="NM4-L1-Iov" secondAttribute="leadingMargin" id="VX7-v2-UKN"/>
<constraint firstItem="CL8-c8-W96" firstAttribute="trailing" secondItem="NM4-L1-Iov" secondAttribute="trailingMargin" id="sVp-RI-2OM"/>
</constraints>
</view>
<connections>
<outlet property="cardStackView" destination="CL8-c8-W96" id="wly-Hz-2Be"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dZP-uD-Gf3" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1892" y="131.78410794602701"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="IJB-WP-ss1">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="op4-yf-pKr" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="QaB-pn-J39">
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="BYZ-38-t0r" kind="relationship" relationship="rootViewController" id="UTh-1x-FVi"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pCu-VV-fi7" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="138.98050974512745"/>
</scene>
</scenes>
Expand Down
45 changes: 45 additions & 0 deletions Example/WOWCardStackView/DetailsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// DetailsViewController.swift
// WOWCardStackView
//
// Created by Zhou Hao on 17/3/17.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import WOWCardStackView

class DetailsViewController: UIViewController, CardStackViewDataSource {

@IBOutlet weak var cardStackView: CardStackView!
var id: Int!
var orderNo: Int = 5

override func viewDidLoad() {
super.viewDidLoad()

self.title = "\(id!)"

cardStackView.register(nib: UINib(nibName: "MyCard", bundle: nil))
cardStackView.dataSource = self

}

func nextCard(in: CardStackView) -> CardView? {
let card = cardStackView.dequeueCardView() as! MyCard
card.numberLabel.text = "\(orderNo)"
orderNo += 1
return card
}

func cardStackView(_ cardStackView: CardStackView, cardAt index: Int) -> CardView {
let card = cardStackView.dequeueCardView() as! MyCard
card.numberLabel.text = "\(index)"
return card
}

func numOfCardInStackView(_ cardStackView: CardStackView) -> Int {
return 5
}

}
12 changes: 12 additions & 0 deletions Example/WOWCardStackView/MyCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,17 @@ import WOWCardStackView

class MyCard: CardView {
@IBOutlet weak var numberLabel: UILabel!

var id: Int

init(id: Int) {
self.id = id
super.init(frame: CGRect.zero)
}

required init?(coder aDecoder: NSCoder) {
self.id = 0
super.init(coder: aDecoder)
}

}
30 changes: 24 additions & 6 deletions Example/WOWCardStackView/MyCard.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,34 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MyCard" customModule="WOWCardStackView_Example" customModuleProvider="target"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="MyCard" customModule="WOWCardStackView_Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="375" height="200"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="300"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ngz-wL-ZLy">
<rect key="frame" x="166.5" y="90" width="42" height="21"/>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="placeholder.jpg" translatesAutoresizingMaskIntoConstraints="NO" id="fkF-YI-OSe">
<rect key="frame" x="0.0" y="0.0" width="375" height="240"/>
<constraints>
<constraint firstAttribute="height" constant="240" id="DXe-0C-9LA"/>
</constraints>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6j4-eA-66Y">
<rect key="frame" x="6" y="259" width="88" height="21"/>
<constraints>
<constraint firstAttribute="height" constant="21" id="jXL-Pv-tZY"/>
<constraint firstAttribute="width" constant="88" id="jkG-49-l0l"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" red="0.01176470588" green="0.66274509800000003" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="Ngz-wL-ZLy" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="RAH-Ae-Ysf"/>
<constraint firstItem="Ngz-wL-ZLy" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="centerY" id="UZy-M5-sUv"/>
<constraint firstItem="6j4-eA-66Y" firstAttribute="top" secondItem="fkF-YI-OSe" secondAttribute="bottom" constant="19" id="3nC-By-N8r"/>
<constraint firstItem="6j4-eA-66Y" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="6" id="DcU-rP-W87"/>
<constraint firstAttribute="trailing" secondItem="fkF-YI-OSe" secondAttribute="trailing" id="LQx-Vu-0GK"/>
<constraint firstItem="fkF-YI-OSe" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" id="T8D-d6-9Cp"/>
<constraint firstItem="fkF-YI-OSe" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" id="lH3-DK-Mdo"/>
<constraint firstAttribute="bottom" secondItem="6j4-eA-66Y" secondAttribute="bottom" constant="20" id="sMK-YU-WGE"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
Expand All @@ -39,8 +53,12 @@
<userDefinedRuntimeAttribute type="boolean" keyPath="isShadowed" value="YES"/>
</userDefinedRuntimeAttributes>
<connections>
<outlet property="numberLabel" destination="Ngz-wL-ZLy" id="v1t-RG-0c1"/>
<outlet property="numberLabel" destination="6j4-eA-66Y" id="aSN-ey-bcs"/>
</connections>
<point key="canvasLocation" x="33.5" y="54"/>
</view>
</objects>
<resources>
<image name="placeholder.jpg" width="1280" height="800"/>
</resources>
</document>
39 changes: 31 additions & 8 deletions Example/WOWCardStackView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,58 @@
import UIKit
import WOWCardStackView

class ViewController: UIViewController, CardStackViewDataSource {
class ViewController: UIViewController, CardStackViewDataSource, CardStackViewDelegate {

@IBOutlet weak var cardStackView: CardStackView!
var orderNo: Int = 3

override func viewDidLoad() {
super.viewDidLoad()

cardStackView.register(nib: UINib(nibName: "MyCard", bundle: nil))
cardStackView.dataSource = self
cardStackView.reloadData()
cardStackView.delegate = self
}

func nextCard(in: CardStackView) -> CardView? {
let card = cardStackView.dequeueCardView() as! MyCard
card.numberLabel.text = "\(orderNo)"
let card = createCard(order: orderNo)
orderNo += 1
return card
}

func cardStackView(_ cardStackView: CardStackView, cardAt index: Int) -> CardView {
let card = cardStackView.dequeueCardView() as! MyCard
card.numberLabel.text = "\(index)"
return card
return createCard(order: index)
}

func numOfCardInStackView(_ cardStackView: CardStackView) -> Int {
return 3
}

public func cardStackView(_: CardStackView, didSelect card: CardView) {
if let card = card as? MyCard {
print("Clicked: \(card.id)")

if let details = self.storyboard?.instantiateViewController(withIdentifier: "DetailsViewController") as? DetailsViewController {
details.id = card.id
self.navigationController?.pushViewController(details, animated: true)
}
}
}

func createCard(order: Int) -> MyCard {
let card = MyCard(id: order)
card.id = order
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
label.font = UIFont(name: "Arial", size: 28)
label.text = "\(order)"
label.textAlignment = .center
label.textColor = UIColor.white
card.addSubview(label)
card.backgroundColor = UIColor.red
card.borderWidth = 1.0
card.borderColor = UIColor.lightGray
card.isShadowed = true
return card
}

}

Binary file added Example/WOWCardStackView/placeholder.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion WOWCardStackView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'WOWCardStackView'
s.version = '0.1.2'
s.version = '0.1.3'
s.summary = 'Swapable Card Stack View in Swift 3.0.'

# This description is used to generate tags and improve search results.
Expand Down
Loading

0 comments on commit 90bee6b

Please sign in to comment.