Commit 73bd9492 by Daniel Dahan

development: navigation bar multi button support - alpha

parent 0f4f4ba0
......@@ -24,11 +24,6 @@ public class BasicCardView : MaterialCardView, Comparable {
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
//
// :name: views
//
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
/**
:name: titleLabelVerticalInset
*/
......@@ -405,6 +400,7 @@ public class BasicCardView : MaterialCardView, Comparable {
// detect all components and create constraints
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// title
if nil != titleLabelContainer && nil != titleLabel {
......
......@@ -24,11 +24,6 @@ public class ImageCardView : MaterialCardView, Comparable {
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
//
// :name: views
//
internal lazy var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
/**
:name: imageViewVerticalInset
*/
......@@ -517,6 +512,7 @@ public class ImageCardView : MaterialCardView, Comparable {
// detect all components and create constraints
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// image
if nil != imageViewContainer && nil != imageView {
......
......@@ -27,6 +27,9 @@ extension MaterialTheme {
public static var buttonVerticalInset: CGFloat = 6
public static var buttonHorizontalInset: CGFloat = 16
public static var navigationVerticalInset: CGFloat = 8
public static var navigationHorizontalInset: CGFloat = 8
}
// fonts
......
......@@ -20,38 +20,97 @@ import UIKit
public class NavigationViewController: UIViewController {
//
// :name: titleLabel
// :name: layoutConstraints
//
internal lazy var layoutConstraints: Array<NSLayoutConstraint> = Array<NSLayoutConstraint>()
/**
:name: maximumTitleLabelHeight
*/
public var maximumTitleLabelHeight: CGFloat = 0 {
didSet {
prepareNavigation()
}
}
/**
:name: titleLabelContainer
*/
public private(set) var titleLabelContainer: UIView?
/**
:name: titleLabel
*/
public var titleLabel: UILabel? {
didSet {
if let v = titleLabel {
v.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(v)
if let t = titleLabel {
// container
if nil == titleLabelContainer {
titleLabelContainer = UIView()
titleLabelContainer!.translatesAutoresizingMaskIntoConstraints = false
titleLabelContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(titleLabelContainer!)
}
// text
titleLabelContainer!.addSubview(t)
t.translatesAutoresizingMaskIntoConstraints = false
t.backgroundColor = MaterialTheme.clear.color
t.font = Roboto.regular
t.numberOfLines = 0
t.lineBreakMode = .ByTruncatingTail
t.textColor = MaterialTheme.white.color
} else {
titleLabelContainer?.removeFromSuperview()
titleLabelContainer = nil
}
prepareNavigation()
}
}
/**
:name: leftButton
:name: leftButtonsContainer
*/
public var leftButton: FlatButton? {
public private(set) var leftButtonsContainer: UIView?
/**
:name: leftButtons
*/
public var leftButtons: Array<MaterialButton>? {
didSet {
if let v = leftButton {
v.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(v)
if nil == leftButtons {
leftButtonsContainer?.removeFromSuperview()
leftButtonsContainer = nil
} else if nil == leftButtonsContainer {
leftButtonsContainer = UIView()
leftButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
leftButtonsContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(leftButtonsContainer!)
}
prepareNavigation()
}
}
/**
:name: rightButton
:name: rightButtonsContainer
*/
public var rightButton: FlatButton? {
public private(set) var rightButtonsContainer: UIView?
/**
:name: rightButtons
*/
public var rightButtons: Array<MaterialButton>? {
didSet {
if let v = rightButton {
v.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(v)
if nil == rightButtons {
rightButtonsContainer?.removeFromSuperview()
rightButtonsContainer = nil
} else if nil == rightButtonsContainer {
rightButtonsContainer = UIView()
rightButtonsContainer!.translatesAutoresizingMaskIntoConstraints = false
rightButtonsContainer!.backgroundColor = MaterialTheme.clear.color
view.addSubview(rightButtonsContainer!)
}
prepareNavigation()
}
}
......@@ -69,12 +128,30 @@ public class NavigationViewController: UIViewController {
super.init(nibName: nil, bundle: nil)
}
/**
:name: init
*/
public init?(titleLabel: UILabel? = nil, leftButtons: Array<MaterialButton>? = nil, rightButtons: Array<MaterialButton>? = nil) {
super.init(nibName: nil, bundle: nil)
prepareProperties(titleLabel, leftButtons: leftButtons, rightButtons: rightButtons)
}
//
// :name: prepareProperties
//
internal func prepareProperties(titleLabel: UILabel?, leftButtons: Array<MaterialButton>?, rightButtons: Array<MaterialButton>?) {
self.titleLabel = titleLabel
self.leftButtons = leftButtons
self.rightButtons = rightButtons
}
//
// :name: viewDidLoad
//
public override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareNavigation()
}
/**
......@@ -102,4 +179,92 @@ public class NavigationViewController: UIViewController {
view.layer.shadowRadius = 1
view.clipsToBounds = false
}
//
// :name: prepareNavigation
//
internal func prepareNavigation() {
// clear all constraints
NSLayoutConstraint.deactivateConstraints(layoutConstraints)
layoutConstraints.removeAll(keepCapacity: false)
// detect all components and create constraints
var verticalFormat: String = "V:|"
var horizontalFormat: String = "H:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
// left buttons
if nil != leftButtonsContainer && (nil != leftButtons) {
// clear for updated constraints
leftButtonsContainer!.removeConstraints(leftButtonsContainer!.constraints)
//container
verticalFormat += "[leftButtonsContainer]"
horizontalFormat += "|[leftButtonsContainer]"
views["leftButtonsContainer"] = leftButtonsContainer!
// leftButtons
var hFormat: String = "H:|"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = leftButtons!.count; i < l; ++i {
let button: MaterialButton = leftButtons![i]
leftButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "-(buttonLeftInset)-[button\(i)]"
Layout.expandToParentVerticallyWithPad(leftButtonsContainer!, child: button, top: 8, bottom: 8)
}
leftButtonsContainer!.addConstraints(Layout.constraint(hFormat, options: [], metrics: ["buttonLeftInset": 8], views: buttonViews))
}
// title
if nil != titleLabelContainer && nil != titleLabel {
// clear for updated constraints
titleLabelContainer!.removeConstraints(titleLabelContainer!.constraints)
// container
verticalFormat += "[titleLabelContainer]"
horizontalFormat += "[titleLabelContainer]"
views["titleLabelContainer"] = titleLabelContainer!
// common text
if 0 == maximumTitleLabelHeight {
Layout.expandToParentWithPad(titleLabelContainer!, child: titleLabel!, top: 8, left: 8, bottom: 8, right: 8)
} else {
Layout.expandToParentHorizontallyWithPad(titleLabelContainer!, child: titleLabel!, left: 8, right: 8)
titleLabelContainer!.addConstraints(Layout.constraint("V:|-(titleLabelTopInset)-[titleLabel(<=maximumTitleLabelHeight)]-(titleLabelBottomInset)-|", options: [], metrics: ["titleLabelTopInset": 8, "titleLabelBottomInset": 8, "maximumTitleLabelHeight": maximumTitleLabelHeight], views: ["titleLabel": titleLabel!]))
}
}
// left buttons
if nil != rightButtonsContainer && (nil != leftButtons) {
// clear for updated constraints
rightButtonsContainer!.removeConstraints(rightButtonsContainer!.constraints)
//container
verticalFormat += "[rightButtonsContainer]"
horizontalFormat += "[rightButtonsContainer]|"
views["rightButtonsContainer"] = rightButtonsContainer!
// leftButtons
var hFormat: String = "H:"
var buttonViews: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
for var i: Int = 0, l: Int = leftButtons!.count; i < l; ++i {
let button: MaterialButton = leftButtons![i]
rightButtonsContainer!.addSubview(button)
buttonViews["button\(i)"] = button
hFormat += "[button\(i)]-(buttonLeftInset)-"
Layout.expandToParentVerticallyWithPad(rightButtonsContainer!, child: button, top: 8, bottom: 8)
}
rightButtonsContainer!.addConstraints(Layout.constraint(hFormat + "|", options: [], metrics: ["buttonLeftInset": 8], views: buttonViews))
}
verticalFormat += "|"
// combine constraints
if 0 < layoutConstraints.count {
layoutConstraints += Layout.constraint(verticalFormat, options: [], metrics: nil, views: views)
layoutConstraints += Layout.constraint(horizontalFormat, options: [], metrics: nil, views: views)
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
}
\ No newline at end of file
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