Commit e4bf38c6 by Daniel Dahan

added ControlView and StatusBarView

parent 5e4b073b
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>CFBundleDevelopmentRegion</key> <key>CFBundleDevelopmentRegion</key>
<string>en</string> <string>en</string>
<key>CFBundleExecutable</key> <key>CFBundleExecutable</key>
......
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; }; 96A71EF61C71127100C0C4AE /* SearchBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71EF51C71127100C0C4AE /* SearchBarView.swift */; };
96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */; }; 96A71F301C72E41100C0C4AE /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */; };
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; }; 96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */; };
96A71FB11C7649F800C0C4AE /* MaterialControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71FB01C7649F800C0C4AE /* MaterialControlView.swift */; }; 96A71FB31C764E3200C0C4AE /* StatusBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71FB21C764E3200C0C4AE /* StatusBarView.swift */; };
96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96A71FB01C7649F800C0C4AE /* ControlView.swift */; };
96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; }; 96D88C1E1C1328D800B91418 /* CaptureView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF51C1328D800B91418 /* CaptureView.swift */; };
96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; }; 96D88C1F1C1328D800B91418 /* CardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF61C1328D800B91418 /* CardView.swift */; };
96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; }; 96D88C201C1328D800B91418 /* CapturePreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */; };
...@@ -146,7 +147,8 @@ ...@@ -146,7 +147,8 @@
96A71EF51C71127100C0C4AE /* SearchBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarView.swift; sourceTree = "<group>"; }; 96A71EF51C71127100C0C4AE /* SearchBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SearchBarView.swift; sourceTree = "<group>"; };
96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; }; 96A71F2F1C72E41100C0C4AE /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; }; 96A71F441C74ABCB00C0C4AE /* MaterialBorder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialBorder.swift; sourceTree = "<group>"; };
96A71FB01C7649F800C0C4AE /* MaterialControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialControlView.swift; sourceTree = "<group>"; }; 96A71FB01C7649F800C0C4AE /* ControlView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ControlView.swift; sourceTree = "<group>"; };
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusBarView.swift; sourceTree = "<group>"; };
96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; }; 96D88BF51C1328D800B91418 /* CaptureView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CaptureView.swift; sourceTree = "<group>"; };
96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; }; 96D88BF61C1328D800B91418 /* CardView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CardView.swift; sourceTree = "<group>"; };
96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; }; 96D88BF71C1328D800B91418 /* CapturePreviewView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CapturePreviewView.swift; sourceTree = "<group>"; };
...@@ -285,6 +287,22 @@ ...@@ -285,6 +287,22 @@
name = Search; name = Search;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
96A71FB41C764EDB00C0C4AE /* StatusBar */ = {
isa = PBXGroup;
children = (
96A71FB21C764E3200C0C4AE /* StatusBarView.swift */,
);
name = StatusBar;
sourceTree = "<group>";
};
96A71FB51C764F3D00C0C4AE /* Control */ = {
isa = PBXGroup;
children = (
96A71FB01C7649F800C0C4AE /* ControlView.swift */,
);
name = Control;
sourceTree = "<group>";
};
96D88BF41C1328D800B91418 /* Sources */ = { 96D88BF41C1328D800B91418 /* Sources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
...@@ -293,6 +311,8 @@ ...@@ -293,6 +311,8 @@
96D88C091C1328D800B91418 /* Material.h */, 96D88C091C1328D800B91418 /* Material.h */,
96D88C501C132A2C00B91418 /* Extensions */, 96D88C501C132A2C00B91418 /* Extensions */,
96D88C541C132A7700B91418 /* Navigation */, 96D88C541C132A7700B91418 /* Navigation */,
96A71FB51C764F3D00C0C4AE /* Control */,
96A71FB41C764EDB00C0C4AE /* StatusBar */,
96A71EF71C71134200C0C4AE /* Search */, 96A71EF71C71134200C0C4AE /* Search */,
96D88C531C132A6900B91418 /* View */, 96D88C531C132A6900B91418 /* View */,
96D88C521C132A5700B91418 /* Layout */, 96D88C521C132A5700B91418 /* Layout */,
...@@ -436,7 +456,6 @@ ...@@ -436,7 +456,6 @@
children = ( children = (
96D88C141C1328D800B91418 /* MaterialView.swift */, 96D88C141C1328D800B91418 /* MaterialView.swift */,
96D88C0D1C1328D800B91418 /* MaterialPulseView.swift */, 96D88C0D1C1328D800B91418 /* MaterialPulseView.swift */,
96A71FB01C7649F800C0C4AE /* MaterialControlView.swift */,
); );
name = View; name = View;
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -627,11 +646,11 @@ ...@@ -627,11 +646,11 @@
96D88C371C1328D800B91418 /* MaterialRadius.swift in Sources */, 96D88C371C1328D800B91418 /* MaterialRadius.swift in Sources */,
960B232F1C383EAA00E96216 /* Material+UIImage+Crop.swift in Sources */, 960B232F1C383EAA00E96216 /* Material+UIImage+Crop.swift in Sources */,
96D88C241C1328D800B91418 /* ImageCardView.swift in Sources */, 96D88C241C1328D800B91418 /* ImageCardView.swift in Sources */,
96A71FB11C7649F800C0C4AE /* MaterialControlView.swift in Sources */,
96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */, 96D88C2B1C1328D800B91418 /* MaterialButton.swift in Sources */,
96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */, 96D88C311C1328D800B91418 /* MaterialKeyframeAnimation.swift in Sources */,
96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */, 96D88C2E1C1328D800B91418 /* MaterialFont.swift in Sources */,
9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */, 9656CD0C1C6BD33700EBCEF1 /* Grid.swift in Sources */,
96A71FB31C764E3200C0C4AE /* StatusBarView.swift in Sources */,
960B23461C38480E00E96216 /* Text.swift in Sources */, 960B23461C38480E00E96216 /* Text.swift in Sources */,
96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */, 96D88C351C1328D800B91418 /* MaterialLayout.swift in Sources */,
96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */, 96D88C2F1C1328D800B91418 /* MaterialGravity.swift in Sources */,
...@@ -667,6 +686,7 @@ ...@@ -667,6 +686,7 @@
96D88C461C1328D800B91418 /* SideNavigationViewController.swift in Sources */, 96D88C461C1328D800B91418 /* SideNavigationViewController.swift in Sources */,
96D88C381C1328D800B91418 /* MaterialShape.swift in Sources */, 96D88C381C1328D800B91418 /* MaterialShape.swift in Sources */,
960B23331C383EAA00E96216 /* Material+UIImage+Size.swift in Sources */, 960B23331C383EAA00E96216 /* Material+UIImage+Size.swift in Sources */,
96A71FB61C7651AA00C0C4AE /* ControlView.swift in Sources */,
96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */, 96A71F451C74ABCB00C0C4AE /* MaterialBorder.swift in Sources */,
96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */, 96A71E911C6FBC2200C0C4AE /* MenuView.swift in Sources */,
96D88C271C1328D800B91418 /* Material+UIFont.swift in Sources */, 96D88C271C1328D800B91418 /* Material+UIFont.swift in Sources */,
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
import UIKit import UIKit
public class MaterialControlView : MaterialView { public class ControlView : MaterialView {
/// ContentView that holds the any desired subviews. /// ContentView that holds the any desired subviews.
public private(set) lazy var contentView: MaterialView = MaterialView() public private(set) lazy var contentView: MaterialView = MaterialView()
......
...@@ -30,22 +30,7 @@ ...@@ -30,22 +30,7 @@
import UIKit import UIKit
@objc(NavigationBarViewDelegate) public class NavigationBarView : StatusBarView {
public protocol NavigationBarViewDelegate : MaterialDelegate {
optional func navigationBarViewDidChangeLayout(navigationBarView: NavigationBarView)
}
public class NavigationBarView : MaterialControlView {
/// Tracks the old frame size.
private var oldFrame: CGRect?
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle {
didSet {
UIApplication.sharedApplication().statusBarStyle = statusBarStyle
}
}
/// Title label. /// Title label.
public var titleLabel: UILabel? { public var titleLabel: UILabel? {
didSet { didSet {
...@@ -66,11 +51,6 @@ public class NavigationBarView : MaterialControlView { ...@@ -66,11 +51,6 @@ public class NavigationBarView : MaterialControlView {
} }
} }
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
}
/** /**
A convenience initializer with parameter settings. A convenience initializer with parameter settings.
- Parameter titleLabel: UILabel for the title. - Parameter titleLabel: UILabel for the title.
...@@ -88,8 +68,6 @@ public class NavigationBarView : MaterialControlView { ...@@ -88,8 +68,6 @@ public class NavigationBarView : MaterialControlView {
// General alignment. // General alignment.
if UIApplication.sharedApplication().statusBarOrientation.isLandscape { if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
grid.contentInset.top = 8
// TitleView alignment. // TitleView alignment.
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
if let d: UILabel = detailLabel { if let d: UILabel = detailLabel {
...@@ -103,10 +81,7 @@ public class NavigationBarView : MaterialControlView { ...@@ -103,10 +81,7 @@ public class NavigationBarView : MaterialControlView {
contentView.grid.contentInset.top = 0 contentView.grid.contentInset.top = 0
} }
} }
height = 44
} else { } else {
grid.contentInset.top = 28
// TitleView alignment. // TitleView alignment.
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
if let d: UILabel = detailLabel { if let d: UILabel = detailLabel {
...@@ -120,32 +95,11 @@ public class NavigationBarView : MaterialControlView { ...@@ -120,32 +95,11 @@ public class NavigationBarView : MaterialControlView {
contentView.grid.contentInset.top = 0 contentView.grid.contentInset.top = 0
} }
} }
height = 64
} }
// Column adjustment.
width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height {
(delegate as? NavigationBarViewDelegate)?.navigationBarViewDidChangeLayout?(self)
oldFrame = frame
}
reloadView() reloadView()
} }
public override func didMoveToSuperview() {
super.didMoveToSuperview()
reloadView()
}
public override func intrinsicContentSize() -> CGSize {
if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
return CGSizeMake(UIScreen.mainScreen().bounds.width, 44)
} else {
return CGSizeMake(UIScreen.mainScreen().bounds.width, 64)
}
}
/// Reloads the view. /// Reloads the view.
public override func reloadView() { public override func reloadView() {
super.reloadView() super.reloadView()
...@@ -170,14 +124,13 @@ public class NavigationBarView : MaterialControlView { ...@@ -170,14 +124,13 @@ public class NavigationBarView : MaterialControlView {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
oldFrame = frame
depth = .Depth1 depth = .Depth1
grid.spacing = 8 grid.spacing = 8
grid.contentInset.left = 8 grid.contentInset.left = 8
grid.contentInset.bottom = 8 grid.contentInset.bottom = 8
grid.contentInset.right = 8 grid.contentInset.right = 8
grid.axis.inherited = false grid.axis.inherited = false
contentView.grid.axis.inherited = false contentView.grid.axis.direction = .Vertical
} }
/** /**
......
...@@ -161,9 +161,9 @@ public class NavigationViewController: UIViewController { ...@@ -161,9 +161,9 @@ public class NavigationViewController: UIViewController {
} }
} }
extension NavigationViewController : NavigationBarViewDelegate { extension NavigationViewController : StatusBarViewDelegate {
/// Monitor layout changes. /// Monitor layout changes.
public func navigationBarViewDidChangeLayout(navigationBarView: NavigationBarView) { public func statusBarViewDidChangeLayout(statusBarView: StatusBarView) {
layoutSubviews() layoutSubviews()
} }
} }
\ No newline at end of file
...@@ -35,63 +35,10 @@ public protocol SearchBarViewDelegate : MaterialDelegate { ...@@ -35,63 +35,10 @@ public protocol SearchBarViewDelegate : MaterialDelegate {
optional func searchBarViewDidChangeLayout(searchBarView: SearchBarView) optional func searchBarViewDidChangeLayout(searchBarView: SearchBarView)
} }
public class SearchBarView : MaterialView { public class SearchBarView : StatusBarView {
/// Tracks the old frame size.
private var oldFrame: CGRect?
/// The UITextField for the searchBar. /// The UITextField for the searchBar.
public private(set) lazy var textField: TextField = TextField() public private(set) lazy var textField: TextField = TextField()
/// StatusBar style.
public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle {
didSet {
UIApplication.sharedApplication().statusBarStyle = statusBarStyle
}
}
/// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset = .None {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets {
get {
return grid.contentInset
}
set(value) {
grid.contentInset = contentInset
reloadView()
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return grid.spacing
}
set(value) {
grid.spacing = spacing
reloadView()
}
}
/// Left side UIControls.
public var leftControls: Array<UIControl>? {
didSet {
reloadView()
}
}
/// Right side UIControls.
public var rightControls: Array<UIControl>? {
didSet {
reloadView()
}
}
/// The UIImage for the clear icon. /// The UIImage for the clear icon.
public var clearButton: UIButton? { public var clearButton: UIButton? {
didSet { didSet {
...@@ -136,39 +83,11 @@ public class SearchBarView : MaterialView { ...@@ -136,39 +83,11 @@ public class SearchBarView : MaterialView {
} }
} }
/**
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. /// A convenience initializer.
public convenience init() { public convenience init() {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64)) self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
} }
/**
A convenience initializer with parameter settings.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
public convenience init?(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
prepareProperties(leftControls, rightControls: rightControls)
}
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
...@@ -183,11 +102,6 @@ public class SearchBarView : MaterialView { ...@@ -183,11 +102,6 @@ public class SearchBarView : MaterialView {
// Column adjustment. // Column adjustment.
width = UIScreen.mainScreen().bounds.width width = UIScreen.mainScreen().bounds.width
grid.axis.columns = Int(width / 48)
if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height {
(delegate as? SearchBarViewDelegate)?.searchBarViewDidChangeLayout?(self)
oldFrame = frame
}
reloadView() reloadView()
} }
...@@ -197,56 +111,8 @@ public class SearchBarView : MaterialView { ...@@ -197,56 +111,8 @@ public class SearchBarView : MaterialView {
} }
/// Reloads the view. /// Reloads the view.
public func reloadView() { public override func reloadView() {
layoutIfNeeded() super.reloadView()
// clear constraints so new ones do not conflict
removeConstraints(constraints)
for v in subviews {
if v != textField {
v.removeFromSuperview()
}
}
// Size of single grid column.
let g: CGFloat = width / CGFloat(0 < grid.columns ? grid.columns : 1)
grid.views = []
textField.grid.columns = grid.axis.columns
// leftControls
if let v: Array<UIControl> = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
textField.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
grid.views?.append(textField)
// rightControls
if let v: Array<UIControl> = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize().width
if let b: UIButton = c as? UIButton {
b.contentEdgeInsets = UIEdgeInsetsZero
}
c.grid.columns = 0 == g ? 1 : Int(ceil(w / g))
textField.grid.columns -= c.grid.columns
addSubview(c)
grid.views?.append(c)
}
}
/// Prepare the clearButton /// Prepare the clearButton
if let v: UIButton = clearButton { if let v: UIButton = clearButton {
...@@ -267,7 +133,6 @@ public class SearchBarView : MaterialView { ...@@ -267,7 +133,6 @@ public class SearchBarView : MaterialView {
*/ */
public override func prepareView() { public override func prepareView() {
super.prepareView() super.prepareView()
oldFrame = frame
grid.spacing = 8 grid.spacing = 8
grid.axis.inherited = false grid.axis.inherited = false
grid.contentInset.left = 8 grid.contentInset.left = 8
...@@ -288,18 +153,6 @@ public class SearchBarView : MaterialView { ...@@ -288,18 +153,6 @@ public class SearchBarView : MaterialView {
textField.backgroundColor = MaterialColor.clear textField.backgroundColor = MaterialColor.clear
textField.clearButtonMode = .Never textField.clearButtonMode = .Never
textField.rightViewMode = .WhileEditing textField.rightViewMode = .WhileEditing
addSubview(textField) contentView.addSubview(textField)
}
/**
Used to trigger property changes that initializers avoid.
- Parameter titleLabel: UILabel for the title.
- Parameter detailLabel: UILabel for the details.
- Parameter leftControls: An Array of UIControls that go on the left side.
- Parameter rightControls: An Array of UIControls that go on the right side.
*/
private func prepareProperties(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
self.leftControls = leftControls
self.rightControls = rightControls
} }
} }
/*
* 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 Material 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(StatusBarViewDelegate)
public protocol StatusBarViewDelegate : MaterialDelegate {
optional func statusBarViewDidChangeLayout(statusBarView: StatusBarView)
}
@objc(StatusBarView)
public class StatusBarView : ControlView {
/// Tracks the old frame size.
private var oldFrame: CGRect?
/// Device status bar style.
public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle {
didSet {
UIApplication.sharedApplication().statusBarStyle = statusBarStyle
}
}
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, 64))
}
public override func layoutSubviews() {
super.layoutSubviews()
// General alignment.
if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
grid.contentInset.top = 8
height = 44
} else {
grid.contentInset.top = 28
height = 64
}
width = UIScreen.mainScreen().bounds.width
if frame.origin.x != oldFrame!.origin.x || frame.origin.y != oldFrame!.origin.y || frame.width != oldFrame!.width || frame.height != oldFrame!.height {
(delegate as? StatusBarViewDelegate)?.statusBarViewDidChangeLayout?(self)
oldFrame = frame
}
reloadView()
}
public override func didMoveToSuperview() {
super.didMoveToSuperview()
reloadView()
}
public override func intrinsicContentSize() -> CGSize {
if UIApplication.sharedApplication().statusBarOrientation.isLandscape {
return CGSizeMake(UIScreen.mainScreen().bounds.width, 44)
} else {
return CGSizeMake(UIScreen.mainScreen().bounds.width, 64)
}
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
public override func prepareView() {
super.prepareView()
oldFrame = frame
}
}
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