Commit 15e00b24 by Daniel Dahan

development: updated RootController calculations, TabBar API, and updated…

development: updated RootController calculations, TabBar API, and updated Divider in Navigational controls
parent 1ca469bb
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
import UIKit import UIKit
open class BarView: ControlView { open class BarView: ControlView {
/// Divider layer.
open internal(set) var divider: Divider!
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
...@@ -68,5 +71,11 @@ open class BarView: ControlView { ...@@ -68,5 +71,11 @@ open class BarView: ControlView {
open override func prepareView() { open override func prepareView() {
super.prepareView() super.prepareView()
depthPreset = .depth1 depthPreset = .depth1
prepareDivider()
}
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
} }
} }
...@@ -42,32 +42,35 @@ open class Divider { ...@@ -42,32 +42,35 @@ open class Divider {
/// A reference to the UIView. /// A reference to the UIView.
internal weak var view: UIView? internal weak var view: UIView?
/// A reference to the height.
internal var height: CGFloat
/// A reference to the divider UIView. /// A reference to the divider UIView.
internal var divider: UIView? internal var line: UIView?
/// Divider color. /// Divider color.
open var color: UIColor? { open var color: UIColor? {
get { get {
return divider?.backgroundColor return line?.backgroundColor
} }
set(value) { set(value) {
guard let v = value else { guard let v = value else {
divider?.removeFromSuperview() line?.removeFromSuperview()
divider = nil line = nil
return return
} }
if nil == divider { if nil == line {
divider = UIView() line = UIView()
divider?.zPosition = 5000 line?.zPosition = 5000
view?.addSubview(divider!) view?.addSubview(line!)
reload() reload()
} }
divider?.backgroundColor = v line?.backgroundColor = v
} }
} }
/// A reference to the dividerAlignment. /// A reference to the dividerAlignment.
internal var alignment = DividerAlignment.top { open var alignment = DividerAlignment.top {
didSet { didSet {
reload() reload()
} }
...@@ -77,8 +80,9 @@ open class Divider { ...@@ -77,8 +80,9 @@ open class Divider {
Initializer that takes in a UIView. Initializer that takes in a UIView.
- Parameter view: A UIView reference. - Parameter view: A UIView reference.
*/ */
internal init(view: UIView?) { internal init(view: UIView?, height: CGFloat = 1) {
self.view = view self.view = view
self.height = height
} }
/// Lays out the divider. /// Lays out the divider.
...@@ -87,19 +91,15 @@ open class Divider { ...@@ -87,19 +91,15 @@ open class Divider {
return return
} }
guard let d = divider else {
return
}
switch alignment { switch alignment {
case .top: case .top:
d.frame = CGRect(x: 0, y: 0, width: v.width, height: 1) line?.frame = CGRect(x: 0, y: 0, width: v.width, height: height)
case .bottom: case .bottom:
d.frame = CGRect(x: 0, y: v.height - 1, width: v.width, height: 1) line?.frame = CGRect(x: 0, y: v.height - height, width: v.width, height: height)
case .left: case .left:
d.frame = CGRect(x: 0, y: 0, width: 1, height: v.height) line?.frame = CGRect(x: 0, y: 0, width: height, height: v.height)
case .right: case .right:
d.frame = CGRect(x: v.width - 1, y: 0, width: 1, height: v.height) line?.frame = CGRect(x: v.width - height, y: 0, width: height, height: v.height)
} }
} }
} }
...@@ -51,8 +51,11 @@ extension UINavigationBar { ...@@ -51,8 +51,11 @@ extension UINavigationBar {
} }
@IBDesignable @IBDesignable
public class NavigationBar: UINavigationBar { open class NavigationBar: UINavigationBar {
public override var intrinsicContentSize: CGSize { /// A reference to the divider.
open internal(set) var divider: Divider!
open override var intrinsicContentSize: CGSize {
switch navigationBarStyle { switch navigationBarStyle {
case .small: case .small:
return CGSize(width: Device.width, height: 32) return CGSize(width: Device.width, height: 32)
...@@ -64,45 +67,48 @@ public class NavigationBar: UINavigationBar { ...@@ -64,45 +67,48 @@ public class NavigationBar: UINavigationBar {
} }
/// NavigationBarStyle value. /// NavigationBarStyle value.
public var navigationBarStyle = NavigationBarStyle.medium open var navigationBarStyle = NavigationBarStyle.medium
internal var animating: Bool = false internal var animating = false
/// Will render the view. /// Will render the view.
public var willRenderView: Bool { open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
} }
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset = EdgeInsetsPreset.none { open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet { didSet {
contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset) contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
} }
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
@IBInspectable public var contentInset = EdgeInsets.zero { @IBInspectable
open var contentInset = EdgeInsets.zero {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
} }
/// A preset wrapper around interimSpace. /// A preset wrapper around interimSpace.
public var interimSpacePreset = InterimSpacePreset.none { open var interimSpacePreset = InterimSpacePreset.none {
didSet { didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset) interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
} }
} }
/// A wrapper around grid.interimSpace. /// A wrapper around grid.interimSpace.
@IBInspectable public var interimSpace: InterimSpace = 0 { @IBInspectable
open var interimSpace: InterimSpace = 0 {
didSet { didSet {
layoutSubviews() layoutSubviews()
} }
} }
/// Grid cell factor. /// Grid cell factor.
@IBInspectable public var gridFactor: CGFloat = 24 { @IBInspectable
open var gridFactor: CGFloat = 24 {
didSet { didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]") assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews() layoutSubviews()
...@@ -113,7 +119,8 @@ public class NavigationBar: UINavigationBar { ...@@ -113,7 +119,8 @@ public class NavigationBar: UINavigationBar {
The back button image writes to the backIndicatorImage property and The back button image writes to the backIndicatorImage property and
backIndicatorTransitionMaskImage property. backIndicatorTransitionMaskImage property.
*/ */
@IBInspectable public var backButtonImage: UIImage? { @IBInspectable
open var backButtonImage: UIImage? {
get { get {
return backIndicatorImage return backIndicatorImage
} }
...@@ -125,7 +132,8 @@ public class NavigationBar: UINavigationBar { ...@@ -125,7 +132,8 @@ public class NavigationBar: UINavigationBar {
} }
/// A property that accesses the backing layer's backgroundColor. /// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? { @IBInspectable
open override var backgroundColor: UIColor? {
didSet { didSet {
barTintColor = backgroundColor barTintColor = backgroundColor
} }
...@@ -156,18 +164,18 @@ public class NavigationBar: UINavigationBar { ...@@ -156,18 +164,18 @@ public class NavigationBar: UINavigationBar {
self.init(frame: .zero) self.init(frame: .zero)
} }
public override func sizeThatFits(_ size: CGSize) -> CGSize { open override func sizeThatFits(_ size: CGSize) -> CGSize {
return intrinsicContentSize return intrinsicContentSize
} }
public override func layoutSublayers(of layer: CALayer) { open override func layoutSublayers(of layer: CALayer) {
super.layoutSublayers(of: layer) super.layoutSublayers(of: layer)
if self.layer == layer { if self.layer == layer {
layoutShape() layoutShape()
} }
} }
public override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
layoutShadowPath() layoutShadowPath()
...@@ -178,9 +186,11 @@ public class NavigationBar: UINavigationBar { ...@@ -178,9 +186,11 @@ public class NavigationBar: UINavigationBar {
if let v = backItem { if let v = backItem {
layoutNavigationItem(item: v) layoutNavigationItem(item: v)
} }
divider?.reload()
} }
public override func pushItem(_ item: UINavigationItem, animated: Bool) { open override func pushItem(_ item: UINavigationItem, animated: Bool) {
super.pushItem(item, animated: animated) super.pushItem(item, animated: animated)
layoutNavigationItem(item: item) layoutNavigationItem(item: item)
} }
...@@ -298,10 +308,11 @@ public class NavigationBar: UINavigationBar { ...@@ -298,10 +308,11 @@ public class NavigationBar: UINavigationBar {
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
backButtonImage = Icon.cm.arrowBack backButtonImage = Icon.cm.arrowBack
let image: UIImage? = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1)) let image = UIImage.imageWithColor(color: Color.clear, size: CGSize(width: 1, height: 1))
shadowImage = image shadowImage = image
setBackgroundImage(image, for: .default) setBackgroundImage(image, for: .default)
backgroundColor = Color.white backgroundColor = Color.white
prepareDivider()
} }
/** /**
...@@ -337,4 +348,10 @@ public class NavigationBar: UINavigationBar { ...@@ -337,4 +348,10 @@ public class NavigationBar: UINavigationBar {
item.contentView!.grid.axis.direction = .vertical item.contentView!.grid.axis.direction = .vertical
return item.contentView! return item.contentView!
} }
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
divider.alignment = .bottom
}
} }
...@@ -72,8 +72,8 @@ open class PageTabBarController: RootController { ...@@ -72,8 +72,8 @@ open class PageTabBarController: RootController {
return return
} }
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
let y = h - p let y = h - p
...@@ -83,6 +83,8 @@ open class PageTabBarController: RootController { ...@@ -83,6 +83,8 @@ open class PageTabBarController: RootController {
rootViewController.view.frame.origin.y = 0 rootViewController.view.frame.origin.y = 0
rootViewController.view.frame.size.height = y rootViewController.view.frame.size.height = y
v.divider.reload()
} }
/** /**
......
...@@ -65,8 +65,8 @@ open class SearchBarController: RootController { ...@@ -65,8 +65,8 @@ open class SearchBarController: RootController {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
...@@ -74,6 +74,8 @@ open class SearchBarController: RootController { ...@@ -74,6 +74,8 @@ open class SearchBarController: RootController {
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p rootViewController.view.frame.size.height = h - p
v.divider.reload()
} }
/** /**
......
...@@ -38,7 +38,17 @@ public enum TabBarLineAlignment: Int { ...@@ -38,7 +38,17 @@ public enum TabBarLineAlignment: Int {
open class TabBar: View { open class TabBar: View {
/// A reference to the line UIView. /// A reference to the line UIView.
open internal(set) var line: UIView! internal var line: UIView!
/// The line color.
open var lineColor: UIColor? {
get {
return line.backgroundColor
}
set(value) {
line.backgroundColor = value
}
}
/// A value for the line alignment. /// A value for the line alignment.
open var lineAlignment = TabBarLineAlignment.bottom { open var lineAlignment = TabBarLineAlignment.bottom {
...@@ -47,6 +57,16 @@ open class TabBar: View { ...@@ -47,6 +57,16 @@ open class TabBar: View {
} }
} }
/// The line height.
open var lineHeight: CGFloat {
get {
return line.height
}
set(value) {
line.height = value
}
}
/// Will render the view. /// Will render the view.
open var willRenderView: Bool { open var willRenderView: Bool {
return 0 < width && 0 < height && nil != superview return 0 < width && 0 < height && nil != superview
...@@ -124,7 +144,7 @@ open class TabBar: View { ...@@ -124,7 +144,7 @@ open class TabBar: View {
b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside) b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
} }
grid.reload() grid.reload()
line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: buttons.first!.width, height: 3) line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - lineHeight : 0, width: buttons.first!.width, height: lineHeight)
} }
divider.reload() divider.reload()
} }
...@@ -160,7 +180,9 @@ open class TabBar: View { ...@@ -160,7 +180,9 @@ open class TabBar: View {
// Prepares the line. // Prepares the line.
private func prepareLine() { private func prepareLine() {
line = UIView() line = UIView()
line.backgroundColor = Color.blueGrey.lighten3 line.zPosition = 5100
lineColor = Color.blueGrey.lighten3
lineHeight = 3
addSubview(line) addSubview(line)
} }
......
...@@ -138,6 +138,7 @@ public class Toolbar: BarView { ...@@ -138,6 +138,7 @@ public class Toolbar: BarView {
super.prepareView() super.prepareView()
prepareTitleLabel() prepareTitleLabel()
prepareDetailLabel() prepareDetailLabel()
prepareDivider()
} }
/// Prepares the titleLabel. /// Prepares the titleLabel.
...@@ -155,4 +156,9 @@ public class Toolbar: BarView { ...@@ -155,4 +156,9 @@ public class Toolbar: BarView {
detailLabel.font = RobotoFont.regularWithSize(size: 12) detailLabel.font = RobotoFont.regularWithSize(size: 12)
detailLabel.textAlignment = .left detailLabel.textAlignment = .left
} }
/// Prepares the divider.
private func prepareDivider() {
divider.alignment = .bottom
}
} }
...@@ -168,8 +168,8 @@ open class ToolbarController: RootController { ...@@ -168,8 +168,8 @@ open class ToolbarController: RootController {
v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20 v.grid.layoutEdgeInsets.top = .phone == Device.userInterfaceIdiom && Device.isLandscape ? 0 : 20
let h = Device.height let h = view.height
let w = Device.width let w = view.width
let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom let p = v.intrinsicContentSize.height + v.grid.layoutEdgeInsets.top + v.grid.layoutEdgeInsets.bottom
v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right v.width = w + v.grid.layoutEdgeInsets.left + v.grid.layoutEdgeInsets.right
...@@ -177,6 +177,8 @@ open class ToolbarController: RootController { ...@@ -177,6 +177,8 @@ open class ToolbarController: RootController {
rootViewController.view.frame.origin.y = p rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p rootViewController.view.frame.size.height = h - p
v.divider.reload()
} }
/** /**
......
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