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