Commit 825c260f by Daniel Dahan

development: Morged BarView and ContentView into Bar, and a base sample project

parent 5d842821
......@@ -8,6 +8,9 @@
location = "container:"
name = "Programmatic">
<FileRef
location = "group:Programmatic/Bar/Bar.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/BottomNavigationController/BottomNavigationController.xcodeproj">
</FileRef>
<FileRef
......
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:Bar.xcodeproj">
</FileRef>
</Workspace>
......@@ -29,60 +29,41 @@
*/
import UIKit
import Material
open class BarView: ContentView {
/// Divider layer.
open internal(set) var divider: Divider!
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
super.init(frame: frame)
}
/**
A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side.
*/
public override init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) {
super.init(leftViews: leftViews, rightViews: rightViews)
}
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
divider.reload()
var window: UIWindow?
func applicationDidFinishLaunching(_ application: UIApplication) {
window = UIWindow(frame: Device.bounds)
window!.rootViewController = ViewController()
window!.makeKeyAndVisible()
}
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
prepareDivider()
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
{
"images" : [
{
"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" : "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"
}
],
"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 {
/// A reference to the Bar.
private var bar: Bar!
/// Left buttons.
private var favoriteButton: IconButton!
/// Right buttons.
private var shareButton: IconButton!
/// Title label.
private var titleLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Color.white
prepareFavoriteButton()
prepareShareButton()
prepareTitleLabel()
prepareBar()
layoutSubviews()
}
private func prepareFavoriteButton() {
favoriteButton = IconButton(image: Icon.favorite, tintColor: Color.white)
favoriteButton.pulseColor = Color.white
}
private func prepareShareButton() {
shareButton = IconButton(image: Icon.cm.share, tintColor: Color.white)
shareButton.pulseColor = Color.white
}
private func prepareTitleLabel() {
titleLabel = UILabel()
titleLabel.text = "Title"
titleLabel.font = RobotoFont.bold(with: 17)
titleLabel.textColor = Color.white
}
private func prepareBar() {
bar = Bar()
bar.contentEdgeInsetsPreset = .square1
bar.backgroundColor = Color.blue.base
bar.leftViews = [favoriteButton]
bar.rightViews = [shareButton]
}
private func layoutSubviews() {
view.layout(bar).horizontally().center()
bar.contentView.layout(titleLabel).edges()
}
}
......@@ -36,7 +36,7 @@ public enum ContentViewAlignment: Int {
case center
}
open class ContentView: View {
open class Bar: View {
/// Should center the contentView.
open var contentViewAlignment = ContentViewAlignment.any {
didSet {
......@@ -44,124 +44,127 @@ open class ContentView: View {
}
}
/// Will render the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
/// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get {
return grid.contentEdgeInsetsPreset
}
set(value) {
grid.contentEdgeInsetsPreset = value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
/// Will render the view.
open var willLayout: Bool {
return 0 < width && 0 < height && nil != superview
}
/// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsetsPreset {
get {
return grid.contentEdgeInsetsPreset
}
set(value) {
grid.contentEdgeInsetsPreset = value
}
}
/// A wrapper around grid.contentInset.
@IBInspectable
open var contentEdgeInsets: EdgeInsets {
get {
return grid.contentEdgeInsets
}
set(value) {
grid.contentEdgeInsets = value
}
}
/// A preset wrapper around interimSpace.
open var interimSpacePreset = InterimSpacePreset.none {
didSet {
get {
return grid.contentEdgeInsets
}
set(value) {
grid.contentEdgeInsets = value
}
}
/// A preset wrapper around interimSpace.
open var interimSpacePreset = InterimSpacePreset.none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
}
}
/// A wrapper around grid.interimSpace.
@IBInspectable
open var interimSpace: InterimSpace {
get {
return grid.interimSpace
}
set(value) {
grid.interimSpace = value
}
}
get {
return grid.interimSpace
}
set(value) {
grid.interimSpace = value
}
}
open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 44)
}
/// Grid cell factor.
@IBInspectable
/// Grid cell factor.
@IBInspectable
open var gridFactor: CGFloat = 24 {
didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews()
}
}
/// ContentView that holds the any desired subviews.
open private(set) lazy var contentView = View()
/// Left side UIViews.
open var leftViews = [UIView]() {
didSet {
didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews()
}
}
/// Divider layer.
open internal(set) var divider: Divider!
/// ContentView that holds the any desired subviews.
open private(set) lazy var contentView = View()
/// Left side UIViews.
open var leftViews = [UIView]() {
didSet {
for v in oldValue {
v.removeFromSuperview()
}
layoutSubviews()
}
}
/// Right side UIViews.
open var rightViews = [UIView]() {
didSet {
}
}
/// Right side UIViews.
open var rightViews = [UIView]() {
didSet {
for v in oldValue {
v.removeFromSuperview()
}
layoutSubviews()
}
}
/**
}
}
/**
An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance.
*/
public required init?(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
/**
}
/**
An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance
using the init() initializer.
- Parameter frame: A CGRect instance.
*/
public override init(frame: CGRect) {
public override init(frame: CGRect) {
super.init(frame: frame)
}
/// Basic initializer.
public init() {
super.init(frame: .zero)
}
/// Basic initializer.
public init() {
super.init(frame: .zero)
frame.size = intrinsicContentSize
}
/**
}
/**
A convenience initializer with parameter settings.
- Parameter leftViews: An Array of UIViews that go on the left side.
- Parameter rightViews: An Array of UIViews that go on the right side.
*/
public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) {
public init(leftViews: [UIView]? = nil, rightViews: [UIView]? = nil) {
self.leftViews = leftViews ?? []
self.rightViews = rightViews ?? []
super.init(frame: .zero)
frame.size = intrinsicContentSize
}
open override func layoutSubviews() {
super.layoutSubviews()
frame.size = intrinsicContentSize
}
open override func layoutSubviews() {
super.layoutSubviews()
guard willLayout else {
return
}
......@@ -216,22 +219,30 @@ open class ContentView: View {
grid.commit()
contentView.grid.commit()
divider.reload()
}
/**
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepare method
to initialize property values and other setup operations.
The super.prepare method should always be called immediately
when subclassing.
*/
open override func prepare() {
super.prepare()
prepareContentView()
}
/// Prepares the contentView.
private func prepareContentView() {
contentView.backgroundColor = nil
}
open override func prepare() {
super.prepare()
prepareContentView()
prepareDivider()
}
/// Prepares the contentView.
private func prepareContentView() {
contentView.backgroundColor = nil
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
}
......@@ -90,7 +90,7 @@ open class ContentCard: PulseView {
}
/// A reference to the bottomBar.
open var bottomBar: BarView? {
open var bottomBar: Bar? {
didSet {
layoutSubviews()
}
......
......@@ -30,7 +30,7 @@
import UIKit
open class SearchBar: BarView {
open class SearchBar: Bar {
/// The UITextField for the searchBar.
open private(set) lazy var textField = UITextField()
......
......@@ -36,7 +36,7 @@ public enum SnackbarStatus: Int {
case hidden
}
open class Snackbar: BarView {
open class Snackbar: Bar {
/// A convenience property to set the titleLabel text.
open var text: String? {
get {
......
......@@ -49,8 +49,8 @@ extension UIViewController {
}
open class StatusBarController: RootController {
/// A reference to the statusBarView.
open private(set) lazy var statusBarView = View()
/// A reference to the statusBar.
open private(set) lazy var statusBar = View()
/**
To execute in the order of the layout chain, override this
......@@ -59,7 +59,7 @@ open class StatusBarController: RootController {
*/
open override func layoutSubviews() {
super.layoutSubviews()
statusBarView.isHidden = Device.isLandscape && .phone == Device.userInterfaceIdiom
statusBar.isHidden = Device.isLandscape && .phone == Device.userInterfaceIdiom
rootViewController.view.frame = view.bounds
}
......@@ -72,13 +72,13 @@ open class StatusBarController: RootController {
*/
open override func prepare() {
super.prepare()
prepareStatusBarView()
prepareStatusBar()
}
/// Prepares the statusBarView.
private func prepareStatusBarView() {
statusBarView.zPosition = 3000
statusBarView.backgroundColor = Color.black.withAlphaComponent(0.12)
view.layout(statusBarView).top(0).horizontally().height(20)
/// Prepares the statusBar.
private func prepareStatusBar() {
statusBar.zPosition = 3000
statusBar.backgroundColor = Color.black.withAlphaComponent(0.12)
view.layout(statusBar).top().horizontally().height(20)
}
}
......@@ -57,7 +57,7 @@ public protocol TabBarDelegate {
optional func tabBarDidSelectButton(tabBar: TabBar, button: UIButton)
}
open class TabBar: BarView {
open class TabBar: Bar {
/// A boolean indicating if the TabBar line is in an animation state.
open internal(set) var isAnimating = false
......
......@@ -32,7 +32,7 @@ import UIKit
private var ToolbarContext: UInt8 = 0
open class Toolbar: BarView {
open class Toolbar: Bar {
/// A convenience property to set the titleLabel text.
open var title: String? {
get {
......
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