Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
376 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-2.63 KB
(97%)
...odeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
21 changes: 21 additions & 0 deletions
21
ScrollStackControllerDemo/Assets.xcassets/hotel.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "hotel.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
113 changes: 113 additions & 0 deletions
113
ScrollStackControllerDemo/Child View Controllers/PricingVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// | ||
// PricingVC.swift | ||
// ScrollStackControllerDemo | ||
// | ||
// Created by Daniele Margutti on 05/10/2019. | ||
// Copyright © 2019 ScrollStackController. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public protocol PricingVCProtocol: class { | ||
func addFee() | ||
} | ||
|
||
public class PricingVC: UIViewController, ScrollStackContainableController { | ||
|
||
public weak var delegate: PricingVCProtocol? | ||
|
||
@IBOutlet public var pricingTable: UITableView! | ||
@IBOutlet public var pricingTableHeightConstraint: NSLayoutConstraint! | ||
|
||
public var pricingTags: [PricingTag] = [ | ||
PricingTag(title: "Night fee", subtitle: "$750 x 3 nights", price: "$2,250.00"), | ||
PricingTag(title: "Hospitality fees", subtitle: "This fee covers services that come with the room", price: "$10.00"), | ||
PricingTag(title: "Property use taxes", subtitle: "Taxes the cost pays to rent their room", price: "$200.00") | ||
] | ||
|
||
public static func create(delegate: PricingVCProtocol) -> PricingVC { | ||
let storyboard = UIStoryboard(name: "Main", bundle: nil) | ||
let vc = storyboard.instantiateViewController(identifier: "PricingVC") as! PricingVC | ||
vc.delegate = delegate | ||
return vc | ||
} | ||
|
||
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? { | ||
let size = CGSize(width: stackView.bounds.size.width, height: 9000) | ||
let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow) | ||
// it's important to set both the height constraint and bottom safe area for table bottom | ||
return best.height | ||
} | ||
|
||
override public func updateViewConstraints() { | ||
pricingTableHeightConstraint.constant = pricingTable.contentSize.height | ||
super.updateViewConstraints() | ||
} | ||
|
||
public override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
pricingTable.rowHeight = UITableView.automaticDimension | ||
pricingTable.estimatedRowHeight = 60 | ||
|
||
pricingTable.reloadData() | ||
pricingTable.sizeToFit() | ||
} | ||
|
||
public func addFee(_ otherFee: PricingTag) { | ||
pricingTags.append(otherFee) | ||
pricingTable.reloadData() | ||
updateViewConstraints() | ||
} | ||
|
||
public func reloadContentFromStackViewRow() { | ||
|
||
} | ||
|
||
@IBAction public func addFee() { | ||
delegate?.addFee() | ||
} | ||
|
||
} | ||
|
||
extension PricingVC: UITableViewDataSource { | ||
|
||
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return pricingTags.count | ||
} | ||
|
||
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: "PricingCell", for: indexPath) as! PricingCell | ||
cell.priceTag = pricingTags[indexPath.row] | ||
return cell | ||
} | ||
|
||
} | ||
|
||
public struct PricingTag { | ||
public let title: String | ||
public let subtitle: String | ||
public let price: String | ||
|
||
public init(title: String, subtitle: String, price: String) { | ||
self.title = title | ||
self.subtitle = subtitle | ||
self.price = price | ||
} | ||
|
||
} | ||
|
||
public class PricingCell: UITableViewCell { | ||
@IBOutlet public var titleLabel: UILabel! | ||
@IBOutlet public var subtitleLabel: UILabel! | ||
@IBOutlet public var priceLabel: UILabel! | ||
|
||
public var priceTag: PricingTag? { | ||
didSet { | ||
titleLabel.text = priceTag?.title ?? "" | ||
subtitleLabel.text = priceTag?.subtitle ?? "" | ||
priceLabel.text = priceTag?.price ?? "" | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
ScrollStackControllerDemo/Child View Controllers/WelcomeVC.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// WelcomeVC.swift | ||
// ScrollStackController | ||
// | ||
// Created by Daniele Margutti on 05/10/2019. | ||
// Copyright © 2019 ScrollStackController. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
public class WelcomeVC: UIViewController, ScrollStackContainableController { | ||
|
||
public static func create() -> WelcomeVC { | ||
let storyboard = UIStoryboard(name: "Main", bundle: nil) | ||
let vc = storyboard.instantiateViewController(identifier: "WelcomeVC") as! WelcomeVC | ||
return vc | ||
} | ||
|
||
public func scrollStackRowSizeForAxis(_ axis: NSLayoutConstraint.Axis, row: ScrollStackRow, in stackView: ScrollStack) -> CGFloat? { | ||
let size = CGSize(width: stackView.bounds.size.width, height: 9000) | ||
let best = self.view.systemLayoutSizeFitting(size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow) | ||
return best.height | ||
} | ||
|
||
public func reloadContentFromStackViewRow() { | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters