Commit cbbcbe5e by Daniel Dahan

fixed issue with BarView types init methods and defaults

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