Commit 10bbe53e by Daniel Dahan

development: added PresenterCard

parent 52972dae
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"images" : [ "images" : [
{ {
"idiom" : "universal", "idiom" : "universal",
"filename" : "CosmicMind.png", "filename" : "frontier.jpg",
"scale" : "1x" "scale" : "1x"
}, },
{ {
......
This image diff could not be displayed because it is too large. You can view the blob instead.
...@@ -52,20 +52,23 @@ class ViewController: UIViewController { ...@@ -52,20 +52,23 @@ class ViewController: UIViewController {
private func prepareImageView() { private func prepareImageView() {
imageView = UIImageView() imageView = UIImageView()
imageView.image = UIImage(named: "CosmicMind") imageView.image = UIImage(named: "frontier.jpg")?.resize(toWidth: view.width)
imageView.clipsToBounds = true imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFit imageView.contentMode = .scaleAspectFill
} }
private func prepareToolbar() { private func prepareToolbar() {
toolbar = Toolbar() toolbar = Toolbar()
toolbar.title = "Title" toolbar.title = "CosmicMind"
toolbar.titleLabel.textAlignment = .left toolbar.titleLabel.textAlignment = .left
toolbar.titleLabel.textColor = Color.white
toolbar.detail = "Detail Description" toolbar.detail = "Build Beautiful Software"
toolbar.detailLabel.textAlignment = .left toolbar.detailLabel.textAlignment = .left
toolbar.detailLabel.textColor = Color.white
toolbar.contentEdgeInsetsPreset = .square3
toolbar.backgroundColor = nil toolbar.backgroundColor = nil
} }
...@@ -77,14 +80,15 @@ class ViewController: UIViewController { ...@@ -77,14 +80,15 @@ class ViewController: UIViewController {
} }
private func prepareFavoriteButton() { private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.blue.base) favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.grey.base)
favoriteButton.pulseColor = Color.blue.base favoriteButton.pulseColor = Color.grey.base
} }
private func prepareBottomBar() { private func prepareBottomBar() {
bottomBar = Bar() bottomBar = Bar()
bottomBar.backgroundColor = nil bottomBar.backgroundColor = nil
bottomBar.leftViews = [favoriteButton] bottomBar.contentEdgeInsetsPreset = .square1
bottomBar.rightViews = [favoriteButton]
} }
private func prepareImageCard() { private func prepareImageCard() {
...@@ -93,7 +97,9 @@ class ViewController: UIViewController { ...@@ -93,7 +97,9 @@ class ViewController: UIViewController {
card.toolbar = toolbar card.toolbar = toolbar
card.contentView = contentView card.contentView = contentView
card.bottomBar = bottomBar card.bottomBar = bottomBar
card.contentEdgeInsetsPreset = .square3
imageView?.layout(toolbar!).height(toolbar!.height + 32)
view.layout(card).top(100).left(20).right(20) view.layout(card).top(100).left(20).right(20)
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
9628645F1D540AF300690B69 /* DynamicFontType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9628645E1D540AF300690B69 /* DynamicFontType.swift */; }; 9628645F1D540AF300690B69 /* DynamicFontType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9628645E1D540AF300690B69 /* DynamicFontType.swift */; };
962864621D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; }; 962864621D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
962864631D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; }; 962864631D54111D00690B69 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 962864611D54111D00690B69 /* JSON.swift */; };
9631A7C11D95E3AC00CFB109 /* PresenterCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */; };
96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; }; 96334EF61C8B84660083986B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96334EF51C8B84660083986B /* Assets.xcassets */; };
963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; }; 963832421B88DFD80015F710 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 963832361B88DFD80015F710 /* Material.framework */; };
963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; }; 963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 963FBEFC1D669510008F8512 /* Snackbar.swift */; };
...@@ -226,6 +227,7 @@ ...@@ -226,6 +227,7 @@
962864591D53FE3E00690B69 /* Material+UIWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIWindow.swift"; sourceTree = "<group>"; }; 962864591D53FE3E00690B69 /* Material+UIWindow.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Material+UIWindow.swift"; sourceTree = "<group>"; };
9628645E1D540AF300690B69 /* DynamicFontType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFontType.swift; sourceTree = "<group>"; }; 9628645E1D540AF300690B69 /* DynamicFontType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFontType.swift; sourceTree = "<group>"; };
962864611D54111D00690B69 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; }; 962864611D54111D00690B69 /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = "<group>"; };
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PresenterCard.swift; sourceTree = "<group>"; };
96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 96334EF51C8B84660083986B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 963832361B88DFD80015F710 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Material.framework; sourceTree = BUILT_PRODUCTS_DIR; };
963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 963832411B88DFD80015F710 /* Material.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Material.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
...@@ -628,6 +630,7 @@ ...@@ -628,6 +630,7 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96BCB75D1CB40DC500C806FE /* Card.swift */, 96BCB75D1CB40DC500C806FE /* Card.swift */,
9631A7C01D95E3AC00CFB109 /* PresenterCard.swift */,
96BCB7621CB40DC500C806FE /* ImageCard.swift */, 96BCB7621CB40DC500C806FE /* ImageCard.swift */,
); );
name = Card; name = Card;
...@@ -1123,6 +1126,7 @@ ...@@ -1123,6 +1126,7 @@
963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */, 963FBEFD1D669510008F8512 /* Snackbar.swift in Sources */,
96BCB7C51CB40DC500C806FE /* MaterialGravity.swift in Sources */, 96BCB7C51CB40DC500C806FE /* MaterialGravity.swift in Sources */,
968C99471D377849000074FF /* Offset.swift in Sources */, 968C99471D377849000074FF /* Offset.swift in Sources */,
9631A7C11D95E3AC00CFB109 /* PresenterCard.swift in Sources */,
96BCB7D51CB40DC500C806FE /* View.swift in Sources */, 96BCB7D51CB40DC500C806FE /* View.swift in Sources */,
96BCB7DE1CB40DC500C806FE /* SearchBar.swift in Sources */, 96BCB7DE1CB40DC500C806FE /* SearchBar.swift in Sources */,
9628645A1D53FE3E00690B69 /* Material+UIWindow.swift in Sources */, 9628645A1D53FE3E00690B69 /* Material+UIWindow.swift in Sources */,
......
...@@ -30,70 +30,15 @@ ...@@ -30,70 +30,15 @@
import UIKit import UIKit
@objc(ToolbarAlignment) open class ImageCard: PresenterCard {
public enum ToolbarAlignment: Int {
case top
case bottom
}
open class ImageCard: Card {
/// A reference to the imageView. /// A reference to the imageView.
@IBInspectable @IBInspectable
open var imageView: UIImageView? { open var imageView: UIImageView? {
didSet { get {
layoutSubviews() return presenterView as? UIImageView
}
}
/// An ImageCardToolbarAlignment value.
open var toolbarAlignment = ToolbarAlignment.bottom {
didSet {
layoutSubviews()
}
}
open override func layout() {
guard let iv = imageView else {
super.layout()
return
}
var format = "V:|"
var views = [String: Any]()
format += "[imageView]"
views["imageView"] = iv
layout(iv).horizontally()
if let v = toolbar {
iv.layout(v).horizontally().bottom()
if .top == toolbarAlignment {
iv.layout(v).top()
} else {
iv.layout(v).bottom()
}
}
if let v = contentView {
format += "-(top)-[contentView]-(bottom)-"
views["contentView"] = v
layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right)
} }
set(value) {
if let v = bottomBar { presenterView = value
format += "[bottomBar]"
views["bottomBar"] = v
layout(v).horizontally()
}
guard 0 < views.count else {
return
} }
var metrics = [String: Any]()
metrics["top"] = contentEdgeInsets.top
metrics["bottom"] = contentEdgeInsets.bottom
addConstraints(Layout.constraint(format: "\(format)|", options: [], metrics: metrics, views: views))
} }
} }
/*
* Copyright (C) 2015 - 2016, Daniel Dahan and CosmicMind, Inc. <http://cosmicmind.io>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of CosmicMind nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import UIKit
@objc(ToolbarAlignment)
public enum ToolbarAlignment: Int {
case top
case bottom
}
open class PresenterCard: Card {
/// A reference to the presenterView.
@IBInspectable
open var presenterView: UIView? {
didSet {
layoutSubviews()
}
}
/// An ImageCardToolbarAlignment value.
open var toolbarAlignment = ToolbarAlignment.bottom {
didSet {
layoutSubviews()
}
}
open override func layout() {
guard let pv = presenterView else {
super.layout()
return
}
var format = "V:|"
var views = [String: Any]()
format += "[presenterView]"
views["presenterView"] = pv
layout(pv).horizontally()
if let v = toolbar {
pv.layout(v).horizontally().bottom()
if .top == toolbarAlignment {
pv.layout(v).top()
} else {
pv.layout(v).bottom()
}
}
if let v = contentView {
format += "-(top)-[contentView]-(bottom)-"
views["contentView"] = v
layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right)
}
if let v = bottomBar {
format += "[bottomBar]"
views["bottomBar"] = v
layout(v).horizontally()
}
guard 0 < views.count else {
return
}
var metrics = [String: Any]()
metrics["top"] = contentEdgeInsets.top
metrics["bottom"] = contentEdgeInsets.bottom
addConstraints(Layout.constraint(format: "\(format)|", options: [], metrics: metrics, views: views))
presenterView?.zPosition = 0
visualLayer.zPosition = 1
contentView?.zPosition = 2
bottomBar?.zPosition = 2
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment