Commit cbbcbe5e by Daniel Dahan

fixed issue with BarView types init methods and defaults

parent bfcb8114
......@@ -59,6 +59,9 @@
location = "group:Programmatic/MenuController/MenuController.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/ControlView/ControlView.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/TabBar/TabBar.xcodeproj">
</FileRef>
<FileRef
......@@ -83,9 +86,6 @@
location = "group:Programmatic/SideNavigationController/SideNavigationController.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/ControlView/ControlView.xcodeproj">
</FileRef>
<FileRef
location = "group:Programmatic/CardView/CardView.xcodeproj">
</FileRef>
<FileRef
......
......@@ -59,17 +59,12 @@ public class BarView : ControlView {
super.init(frame: frame)
}
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
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 override init(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
public override init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(leftControls: leftControls, rightControls: rightControls)
}
......
......@@ -73,8 +73,16 @@ public class ControlView : MaterialView {
}
}
/// Grid cell factor.
@IBInspectable public var gridFactor: CGFloat = 24 {
didSet {
assert(0 < gridFactor, "[Material Error: gridFactor must be greater than 0.]")
layoutSubviews()
}
}
/// ContentView that holds the any desired subviews.
public private(set) lazy var contentView: MaterialView = MaterialView()
public private(set) var contentView: MaterialView!
/// Left side UIControls.
public var leftControls: Array<UIControl>? {
......@@ -136,7 +144,6 @@ public class ControlView : MaterialView {
public init() {
super.init(frame: CGRectZero)
frame.size = intrinsicContentSize()
frame.size.width = MaterialDevice.width
prepareView()
}
......@@ -147,6 +154,7 @@ public class ControlView : MaterialView {
*/
public init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(frame: CGRectZero)
frame.size = intrinsicContentSize()
prepareView()
prepareProperties(leftControls, rightControls: rightControls)
}
......@@ -156,8 +164,7 @@ public class ControlView : MaterialView {
if willRenderView {
layoutIfNeeded()
let factor: CGFloat = 24
if let g: Int = Int(width / factor) {
if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1
grid.views = []
......@@ -172,7 +179,7 @@ public class ControlView : MaterialView {
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / factor)
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
......@@ -192,7 +199,7 @@ public class ControlView : MaterialView {
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsetsZero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / factor)
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
......@@ -241,6 +248,7 @@ public class ControlView : MaterialView {
/// Prepares the contentView.
private func prepareContentView() {
contentView = MaterialView()
contentView.backgroundColor = nil
addSubview(contentView)
}
......
......@@ -111,17 +111,12 @@ public class SearchBar : BarView {
super.init(frame: frame)
}
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
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 override init(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
public override init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(leftControls: leftControls, rightControls: rightControls)
}
......
......@@ -59,21 +59,23 @@ public class SearchBarController : BarController {
/// Layout subviews.
public func layoutSubviews() {
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
searchBar.contentInset.top = 4
} else {
searchBar.contentInset.top = 24
if let v: SearchBar = searchBar {
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
v.contentInset.top = 4
} else {
v.contentInset.top = 24
}
let h: CGFloat = MaterialDevice.height
let w: CGFloat = MaterialDevice.width
let p: CGFloat = searchBar.intrinsicContentSize().height
v.width = w
v.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
}
let h: CGFloat = MaterialDevice.height
let w: CGFloat = MaterialDevice.width
let p: CGFloat = searchBar.intrinsicContentSize().height
searchBar.width = w
searchBar.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
}
/**
......
......@@ -50,12 +50,7 @@ public class TextField : UITextField {
}
}
/**
This property adds a padding to placeholder y position animation
*/
public var placeholderAnimationPadding: CGFloat = 0
/// A property that accesses the backing layer's backgroundColor.
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable public override var backgroundColor: UIColor? {
didSet {
layer.backgroundColor = backgroundColor?.CGColor
......@@ -233,9 +228,6 @@ public class TextField : UITextField {
}
}
/// Vertical distance of detail label to divider
public var detailDistance: CGFloat = 8
/// Vertical distance for the detailLabel from the divider.
@IBInspectable public var detailVerticalDistanceFromDivider: CGFloat = 8 {
didSet {
......
......@@ -74,17 +74,12 @@ public class Toolbar : BarView {
super.init(frame: frame)
}
/// Convenience initializer.
public convenience init() {
self.init(frame: CGRectZero)
}
/**
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 override init(leftControls: Array<UIControl>?, rightControls: Array<UIControl>?) {
public override init(leftControls: Array<UIControl>? = nil, rightControls: Array<UIControl>? = nil) {
super.init(leftControls: leftControls, rightControls: rightControls)
}
......
......@@ -158,21 +158,23 @@ public class ToolbarController : BarController {
/// Layout subviews.
public func layoutSubviews() {
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
toolbar.contentInset.top = 4
} else {
toolbar.contentInset.top = 24
if let v: Toolbar = toolbar {
if .iPhone == MaterialDevice.type && MaterialDevice.isLandscape {
v.contentInset.top = 4
} else {
v.contentInset.top = 24
}
let h: CGFloat = MaterialDevice.height
let w: CGFloat = MaterialDevice.width
let p: CGFloat = v.intrinsicContentSize().height
v.width = w
v.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
}
let h: CGFloat = MaterialDevice.height
let w: CGFloat = MaterialDevice.width
let p: CGFloat = toolbar.intrinsicContentSize().height
toolbar.width = w
toolbar.height = p
rootViewController.view.frame.origin.y = p
rootViewController.view.frame.size.height = h - p
}
/**
......
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