Skip to content

Commit

Permalink
Added support for any custom card size
Browse files Browse the repository at this point in the history
  • Loading branch information
Sundin authored and arneson committed Oct 27, 2017
1 parent 140b315 commit 2e39ce1
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Example/KSSwipeStack/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?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="vXZ-lx-hvc">
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand All @@ -19,7 +19,7 @@
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS" customClass="SwipeView" customModule="KSSwipeStack">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<connections>
Expand Down
4 changes: 2 additions & 2 deletions Example/KSSwipeStack/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class ViewController: UIViewController {
/// Example implementation of the data protocol, a representation of the data you wish to swipe in the stack, ex. users, concerts etc.
/// This will be the data return by a successful swipe.
class ExampleData: SwipableData {
func getView() -> SwipableView {
let view = ExampleCard()
func getView(with frame: CGRect) -> SwipableView {
let view = ExampleCard(frame: frame)
view.setData(self)
return view
}
Expand Down
2 changes: 1 addition & 1 deletion KSSwipeStack/Classes/SwipableData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public protocol SwipableData {
/**
- returns: The view to be rendered in the card stack representing this piece of data.
*/
func getView() -> SwipableView
func getView(with frame: CGRect) -> SwipableView
}
2 changes: 0 additions & 2 deletions KSSwipeStack/Classes/SwipableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ open class SwipableView: UIView {

public override init(frame: CGRect) {
super.init(frame: frame)

self.frame = UIScreen.main.bounds
}

required public init?(coder aDecoder: NSCoder) {
Expand Down
4 changes: 2 additions & 2 deletions KSSwipeStack/Classes/SwipeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class SwipeView: UIView {
- parameter data: The data the new card represents.
*/
public func addCardToTop(_ data: SwipableData) {
let renderedCard = renderCard(data.getView())
let renderedCard = renderCard(data.getView(with: frame))
renderedCards.insert(renderedCard, at: 0)
addSubview(renderedCard)
bringSubview(toFront: renderedCard)
Expand Down Expand Up @@ -136,7 +136,7 @@ public class SwipeView: UIView {
Fills the card stack by rendering new cards from the dataset if needed.
*/
private func fillStack() {
let card = renderCard(dataset.removeFirst().getView())
let card = renderCard(dataset.removeFirst().getView(with: frame))
self.renderedCards.append(card)
if self.renderedCards.count < options.maxRenderedCards, !dataset.isEmpty {
fillStack()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ class ExampleCard: SwipableView {
### Create a simple data model implementing the protocol [SwipableData](https://github.com/Kicksort/KSSwipeStack/KSSwipeStack/Classes/SwipableData.swift).
The protocol contains only one method, getView, in which you need to return a [SwipableView](https://github.com/Kicksort/KSSwipeStack/KSSwipeStack/Classes/SwipableView.swift).
```swift
func getView() -> SwipableView {
let view = ExampleCard()
func getView(with frame: CGRect) -> SwipableView {
let view = ExampleCard(frame: frame)
view.setData(self)
return view
}
Expand Down

0 comments on commit 2e39ce1

Please sign in to comment.