Commit 52972dae by Daniel Dahan

development: updated Card and ImageCard

parent 29eff722
...@@ -23,6 +23,9 @@ ...@@ -23,6 +23,9 @@
location = "group:Programmatic/Card/Card.xcodeproj"> location = "group:Programmatic/Card/Card.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
location = "group:Programmatic/ImageCard/ImageCard.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/Layer/Layer.xcodeproj"> location = "group:Programmatic/Layer/Layer.xcodeproj">
</FileRef> </FileRef>
<FileRef <FileRef
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
import Material import Material
class ViewController: UIViewController { class ViewController: UIViewController {
private var titleBar: Toolbar! private var toolbar: Toolbar!
private var contentView: UILabel! private var contentView: UILabel!
private var bottomBar: Bar! private var bottomBar: Bar!
private var favoriteButton: IconButton! private var favoriteButton: IconButton!
...@@ -41,18 +41,18 @@ class ViewController: UIViewController { ...@@ -41,18 +41,18 @@ class ViewController: UIViewController {
super.viewDidLoad() super.viewDidLoad()
view.backgroundColor = Color.grey.lighten5 view.backgroundColor = Color.grey.lighten5
prepareTitleBar() prepareToolbar()
prepareContentView() prepareContentView()
prepareFavoriteButton() prepareFavoriteButton()
prepareBottomBar() prepareBottomBar()
prepareCard() prepareCard()
} }
private func prepareTitleBar() { private func prepareToolbar() {
titleBar = Toolbar() toolbar = Toolbar()
titleBar.title = "Title" toolbar.title = "Title"
titleBar.detail = "Detail Description" toolbar.detail = "Detail Description"
titleBar.backgroundColor = nil toolbar.backgroundColor = nil
} }
private func prepareContentView() { private func prepareContentView() {
...@@ -75,8 +75,7 @@ class ViewController: UIViewController { ...@@ -75,8 +75,7 @@ class ViewController: UIViewController {
private func prepareCard() { private func prepareCard() {
let card = Card() let card = Card()
card.pulseAnimation = .pointWithBacking card.toolbar = toolbar
card.titleBar = titleBar
card.contentView = contentView card.contentView = contentView
card.bottomBar = bottomBar card.bottomBar = bottomBar
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:ImageCard.xcodeproj">
</FileRef>
</Workspace>
/*
* 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
import Material
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
window = UIWindow(frame: Device.bounds)
window!.rootViewController = ViewController()
window!.makeKeyAndVisible()
}
}
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "83.5x83.5",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
{
"images" : [
{
"idiom" : "universal",
"filename" : "CosmicMind.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="EHf-IW-A2E">
<objects>
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
/*
* 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
import Material
class ViewController: UIViewController {
private var imageView: UIImageView!
private var toolbar: Toolbar!
private var contentView: UILabel!
private var bottomBar: Bar!
private var favoriteButton: IconButton!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.grey.lighten5
prepareImageView()
prepareToolbar()
prepareContentView()
prepareFavoriteButton()
prepareBottomBar()
prepareImageCard()
}
private func prepareImageView() {
imageView = UIImageView()
imageView.image = UIImage(named: "CosmicMind")
imageView.clipsToBounds = true
imageView.contentMode = .scaleAspectFit
}
private func prepareToolbar() {
toolbar = Toolbar()
toolbar.title = "Title"
toolbar.titleLabel.textAlignment = .left
toolbar.detail = "Detail Description"
toolbar.detailLabel.textAlignment = .left
toolbar.backgroundColor = nil
}
private func prepareContentView() {
contentView = UILabel()
contentView.numberOfLines = 0
contentView.text = "It’s been a while, have you read any new books lately?"
contentView.font = RobotoFont.regular(with: 14)
}
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.blue.base)
favoriteButton.pulseColor = Color.blue.base
}
private func prepareBottomBar() {
bottomBar = Bar()
bottomBar.backgroundColor = nil
bottomBar.leftViews = [favoriteButton]
}
private func prepareImageCard() {
let card = ImageCard()
card.imageView = imageView
card.toolbar = toolbar
card.contentView = contentView
card.bottomBar = bottomBar
view.layout(card).top(100).left(20).right(20)
}
}
...@@ -59,28 +59,9 @@ open class Card: PulseView { ...@@ -59,28 +59,9 @@ open class Card: PulseView {
} }
} }
/// A preset wrapper around interimSpace. /// A reference to the toolbar.
open var interimSpacePreset = InterimSpacePreset.none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open var interimSpace: InterimSpace {
get {
return grid.interimSpace
}
set(value) {
grid.interimSpace = value
layoutSubviews()
}
}
/// A reference to the titleBar.
@IBInspectable @IBInspectable
open var titleBar: Toolbar? { open var toolbar: Toolbar? {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
...@@ -125,13 +106,13 @@ open class Card: PulseView { ...@@ -125,13 +106,13 @@ open class Card: PulseView {
/** /**
A convenience initiazlier. A convenience initiazlier.
- Parameter titleBar: An optional Toolbar. - Parameter toolbar: An optional Toolbar.
- Parameter contentView: An optional UIView. - Parameter contentView: An optional UIView.
- Parameter bottomBar: An optional Bar. - Parameter bottomBar: An optional Bar.
*/ */
public convenience init?(titleBar: Toolbar?, contentView: UIView?, bottomBar: Bar?) { public convenience init?(toolbar: Toolbar?, contentView: UIView?, bottomBar: Bar?) {
self.init(frame: .zero) self.init(frame: .zero)
prepareProperties(titleBar: titleBar, contentView: contentView, bottomBar: bottomBar) prepareProperties(toolbar: toolbar, contentView: contentView, bottomBar: bottomBar)
} }
open override func layoutSubviews() { open override func layoutSubviews() {
...@@ -146,25 +127,30 @@ open class Card: PulseView { ...@@ -146,25 +127,30 @@ open class Card: PulseView {
v.removeFromSuperview() v.removeFromSuperview()
} }
var format = "V:|-(top)" layout()
}
/// Lays out view.
open func layout() {
var format = "V:|"
var views = [String: Any]() var views = [String: Any]()
if let v = titleBar { if let v = toolbar {
format += "-[titleBar]" format += "[toolbar]"
views["titleBar"] = v views["toolbar"] = v
layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right) layout(v).horizontally()
} }
if let v = contentView { if let v = contentView {
format += (nil == titleBar ? "" : "-(interimSpace)") + "-[contentView]" format += "-(top)-[contentView]-(bottom)-"
views["contentView"] = v views["contentView"] = v
layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right) layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right)
} }
if let v = bottomBar { if let v = bottomBar {
format += (nil == titleBar && nil == contentView ? "" : "-(interimSpace)") + "-[bottomBar]" format += "[bottomBar]"
views["bottomBar"] = v views["bottomBar"] = v
layout(v).horizontally(left: contentEdgeInsets.left, right: contentEdgeInsets.right) layout(v).horizontally()
} }
guard 0 < views.count else { guard 0 < views.count else {
...@@ -174,9 +160,8 @@ open class Card: PulseView { ...@@ -174,9 +160,8 @@ open class Card: PulseView {
var metrics = [String: Any]() var metrics = [String: Any]()
metrics["top"] = contentEdgeInsets.top metrics["top"] = contentEdgeInsets.top
metrics["bottom"] = contentEdgeInsets.bottom metrics["bottom"] = contentEdgeInsets.bottom
metrics["interimSpace"] = interimSpace
addConstraints(Layout.constraint(format: "\(format)-(bottom)-|", options: [], metrics: metrics, views: views)) addConstraints(Layout.constraint(format: "\(format)|", options: [], metrics: metrics, views: views))
} }
/** /**
...@@ -189,20 +174,17 @@ open class Card: PulseView { ...@@ -189,20 +174,17 @@ open class Card: PulseView {
open override func prepare() { open override func prepare() {
super.prepare() super.prepare()
depthPreset = .depth1 depthPreset = .depth1
pulseAnimation = .none
contentEdgeInsetsPreset = .square1
interimSpacePreset = .interimSpace3
cornerRadiusPreset = .cornerRadius1 cornerRadiusPreset = .cornerRadius1
} }
/** /**
A preparation method that sets the base UI elements. A preparation method that sets the base UI elements.
- Parameter titleBar: An optional Toolbar. - Parameter toolbar: An optional Toolbar.
- Parameter contentView: An optional UIView. - Parameter contentView: An optional UIView.
- Parameter bottomBar: An optional Bar. - Parameter bottomBar: An optional Bar.
*/ */
internal func prepareProperties(titleBar: Toolbar?, contentView: UIView?, bottomBar: Bar?) { internal func prepareProperties(toolbar: Toolbar?, contentView: UIView?, bottomBar: Bar?) {
self.titleBar = titleBar self.toolbar = toolbar
self.contentView = contentView self.contentView = contentView
self.bottomBar = bottomBar self.bottomBar = bottomBar
} }
......
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