Skip to content

Commit 2e39ce1

Browse files
Sundinarneson
authored andcommitted
Added support for any custom card size
1 parent 140b315 commit 2e39ce1

6 files changed

Lines changed: 10 additions & 12 deletions

File tree

Example/KSSwipeStack/Base.lproj/Main.storyboard

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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="vXZ-lx-hvc">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1010
</dependencies>
1111
<scenes>
@@ -19,7 +19,7 @@
1919
</layoutGuides>
2020
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS" customClass="SwipeView" customModule="KSSwipeStack">
2121
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
22-
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22+
<autoresizingMask key="autoresizingMask"/>
2323
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2424
</view>
2525
<connections>

Example/KSSwipeStack/ViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ class ViewController: UIViewController {
4848
/// Example implementation of the data protocol, a representation of the data you wish to swipe in the stack, ex. users, concerts etc.
4949
/// This will be the data return by a successful swipe.
5050
class ExampleData: SwipableData {
51-
func getView() -> SwipableView {
52-
let view = ExampleCard()
51+
func getView(with frame: CGRect) -> SwipableView {
52+
let view = ExampleCard(frame: frame)
5353
view.setData(self)
5454
return view
5555
}

KSSwipeStack/Classes/SwipableData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ public protocol SwipableData {
1515
/**
1616
- returns: The view to be rendered in the card stack representing this piece of data.
1717
*/
18-
func getView() -> SwipableView
18+
func getView(with frame: CGRect) -> SwipableView
1919
}

KSSwipeStack/Classes/SwipableView.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ open class SwipableView: UIView {
1515

1616
public override init(frame: CGRect) {
1717
super.init(frame: frame)
18-
19-
self.frame = UIScreen.main.bounds
2018
}
2119

2220
required public init?(coder aDecoder: NSCoder) {

KSSwipeStack/Classes/SwipeView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public class SwipeView: UIView {
8181
- parameter data: The data the new card represents.
8282
*/
8383
public func addCardToTop(_ data: SwipableData) {
84-
let renderedCard = renderCard(data.getView())
84+
let renderedCard = renderCard(data.getView(with: frame))
8585
renderedCards.insert(renderedCard, at: 0)
8686
addSubview(renderedCard)
8787
bringSubview(toFront: renderedCard)
@@ -136,7 +136,7 @@ public class SwipeView: UIView {
136136
Fills the card stack by rendering new cards from the dataset if needed.
137137
*/
138138
private func fillStack() {
139-
let card = renderCard(dataset.removeFirst().getView())
139+
let card = renderCard(dataset.removeFirst().getView(with: frame))
140140
self.renderedCards.append(card)
141141
if self.renderedCards.count < options.maxRenderedCards, !dataset.isEmpty {
142142
fillStack()

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class ExampleCard: SwipableView {
9393
### Create a simple data model implementing the protocol [SwipableData](https://github.com/Kicksort/KSSwipeStack/KSSwipeStack/Classes/SwipableData.swift).
9494
The protocol contains only one method, getView, in which you need to return a [SwipableView](https://github.com/Kicksort/KSSwipeStack/KSSwipeStack/Classes/SwipableView.swift).
9595
```swift
96-
func getView() -> SwipableView {
97-
let view = ExampleCard()
96+
func getView(with frame: CGRect) -> SwipableView {
97+
let view = ExampleCard(frame: frame)
9898
view.setData(self)
9999
return view
100100
}

0 commit comments

Comments
 (0)