Commit 0ff4ab03 by Daniel Dahan

added contentsGravityPreset where appropriate

parent 77e68079
...@@ -63,7 +63,7 @@ class FeedViewController: UIViewController { ...@@ -63,7 +63,7 @@ class FeedViewController: UIViewController {
menuButton.pulseScale = false menuButton.pulseScale = false
menuButton.setImage(image, forState: .Normal) menuButton.setImage(image, forState: .Normal)
menuButton.setImage(image, forState: .Highlighted) menuButton.setImage(image, forState: .Highlighted)
menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside) // menuButton.addTarget(self, action: "handleMenuButton", forControlEvents: .TouchUpInside)
// Switch control. // Switch control.
let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small) let switchControl: MaterialSwitch = MaterialSwitch(state: .Off, style: .LightContent, size: .Small)
...@@ -75,7 +75,7 @@ class FeedViewController: UIViewController { ...@@ -75,7 +75,7 @@ class FeedViewController: UIViewController {
searchButton.pulseScale = false searchButton.pulseScale = false
searchButton.setImage(image, forState: .Normal) searchButton.setImage(image, forState: .Normal)
searchButton.setImage(image, forState: .Highlighted) searchButton.setImage(image, forState: .Highlighted)
searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside) // searchButton.addTarget(self, action: "handleSearchButton", forControlEvents: .TouchUpInside)
navigationController?.navigationBar.leftControls = [menuButton] navigationController?.navigationBar.leftControls = [menuButton]
navigationController?.navigationBar.rightControls = [switchControl, searchButton] navigationController?.navigationBar.rightControls = [switchControl, searchButton]
......
...@@ -109,7 +109,7 @@ class ViewController: UIViewController { ...@@ -109,7 +109,7 @@ class ViewController: UIViewController {
cardView.pulseColor = nil cardView.pulseColor = nil
cardView.image = UIImage(named: "Material-iTunesArtWork")?.resize(toHeight: 150) cardView.image = UIImage(named: "Material-iTunesArtWork")?.resize(toHeight: 150)
cardView.contentsGravity = .BottomRight cardView.contentsGravityPreset = .BottomRight
// Title label. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
...@@ -154,7 +154,7 @@ class ViewController: UIViewController { ...@@ -154,7 +154,7 @@ class ViewController: UIViewController {
// Image. // Image.
cardView.image = UIImage(named: "Graph")?.resize(toHeight: 150) cardView.image = UIImage(named: "Graph")?.resize(toHeight: 150)
cardView.contentsGravity = .Right cardView.contentsGravityPreset = .Right
// Title label. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
......
...@@ -191,7 +191,7 @@ class ViewController: UIViewController { ...@@ -191,7 +191,7 @@ class ViewController: UIViewController {
var image: UIImage? = UIImage(named: "VeganCakeFull") var image: UIImage? = UIImage(named: "VeganCakeFull")
let imageView: MaterialView = MaterialView() let imageView: MaterialView = MaterialView()
imageView.image = image imageView.image = image
imageView.contentsGravity = .ResizeAspectFill imageView.contentsGravityPreset = .ResizeAspectFill
cardView.addSubview(imageView) cardView.addSubview(imageView)
let contentView: MaterialView = MaterialView() let contentView: MaterialView = MaterialView()
...@@ -288,7 +288,7 @@ class ViewController: UIViewController { ...@@ -288,7 +288,7 @@ class ViewController: UIViewController {
var image: UIImage? = UIImage(named: "CosmicMindInverted") var image: UIImage? = UIImage(named: "CosmicMindInverted")
let imageView: MaterialView = MaterialView() let imageView: MaterialView = MaterialView()
imageView.image = image imageView.image = image
imageView.contentsGravity = .ResizeAspectFill imageView.contentsGravityPreset = .ResizeAspectFill
cardView.addSubview(imageView) cardView.addSubview(imageView)
let contentView: MaterialView = MaterialView() let contentView: MaterialView = MaterialView()
...@@ -387,17 +387,17 @@ class ViewController: UIViewController { ...@@ -387,17 +387,17 @@ class ViewController: UIViewController {
let leftImageView: MaterialView = MaterialView() let leftImageView: MaterialView = MaterialView()
leftImageView.image = image leftImageView.image = image
leftImageView.contentsGravity = .ResizeAspectFill leftImageView.contentsGravityPreset = .ResizeAspectFill
cardView.addSubview(leftImageView) cardView.addSubview(leftImageView)
let topImageView: MaterialView = MaterialView() let topImageView: MaterialView = MaterialView()
topImageView.image = image topImageView.image = image
topImageView.contentsGravity = .ResizeAspectFill topImageView.contentsGravityPreset = .ResizeAspectFill
cardView.addSubview(topImageView) cardView.addSubview(topImageView)
let bottomImageView: MaterialView = MaterialView() let bottomImageView: MaterialView = MaterialView()
bottomImageView.image = image bottomImageView.image = image
bottomImageView.contentsGravity = .ResizeAspectFill bottomImageView.contentsGravityPreset = .ResizeAspectFill
cardView.addSubview(bottomImageView) cardView.addSubview(bottomImageView)
let contentView: MaterialView = MaterialView() let contentView: MaterialView = MaterialView()
......
...@@ -100,7 +100,7 @@ class ViewController: UIViewController { ...@@ -100,7 +100,7 @@ class ViewController: UIViewController {
// Image. // Image.
secondCardView.image = UIImage(named: "Graph")?.resize(toHeight: 100) secondCardView.image = UIImage(named: "Graph")?.resize(toHeight: 100)
secondCardView.contentsGravity = .TopLeft secondCardView.contentsGravityPreset = .TopLeft
// Title label. // Title label.
let titleLabel: UILabel = UILabel() let titleLabel: UILabel = UILabel()
......
...@@ -152,13 +152,14 @@ public class ImageCardView : MaterialPulseView { ...@@ -152,13 +152,14 @@ public class ImageCardView : MaterialPulseView {
} }
} }
/** /// Determines how content should be aligned within the visualLayer's bounds.
:name: contentsGravity public override var contentsGravity: String {
*/ get {
public override var contentsGravity: MaterialGravity { return nil == imageLayer ? "" : imageLayer!.contentsGravity
didSet { }
set(value) {
prepareImageLayer() prepareImageLayer()
imageLayer?.contentsGravity = MaterialGravityToString(contentsGravity) imageLayer?.contentsGravity = value
} }
} }
......
...@@ -33,6 +33,28 @@ import UIKit ...@@ -33,6 +33,28 @@ import UIKit
@objc(MaterialCollectionViewCell) @objc(MaterialCollectionViewCell)
public class MaterialCollectionViewCell : UICollectionViewCell { public class MaterialCollectionViewCell : UICollectionViewCell {
/** /**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
A base delegate reference used when subclassing MaterialView.
*/
public weak var delegate: MaterialDelegate?
/// Sets whether the scaling animation should be used.
public lazy var pulseScale: Bool = true
/// The opcaity value for the pulse animation.
public var pulseColorOpacity: CGFloat = 0.25
/// The color of the pulse effect.
public var pulseColor: UIColor?
/**
A property that manages an image for the visualLayer's contents A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents property. Images should not be set to the backing layer's contents
property to avoid conflicts when using clipsToBounds. property to avoid conflicts when using clipsToBounds.
...@@ -43,10 +65,62 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -43,10 +65,62 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
} }
} }
/// Determines how content should be aligned within the visualLayer's bounds. /**
public var contentsGravity: MaterialGravity { Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows
much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched.
*/
public var contentsRect: CGRect {
get {
return visualLayer.contentsRect
}
set(value) {
visualLayer.contentsRect = value
}
}
/**
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
*/
public var contentsCenter: CGRect {
get {
return visualLayer.contentsCenter
}
set(value) {
visualLayer.contentsCenter = value
}
}
/**
A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the MaterialDevice.scale.
*/
public var contentsScale: CGFloat {
get {
return visualLayer.contentsScale
}
set(value) {
visualLayer.contentsScale = value
}
}
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet { didSet {
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity) contentsGravity = MaterialGravityToString(contentsGravityPreset)
}
}
/// Determines how content should be aligned within the visualLayer's bounds.
public var contentsGravity: String {
get {
return visualLayer.contentsGravity
}
set(value) {
visualLayer.contentsGravity = value
} }
} }
...@@ -88,28 +162,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -88,28 +162,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
} }
/** /**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
A base delegate reference used when subclassing MaterialView.
*/
public weak var delegate: MaterialDelegate?
/// Sets whether the scaling animation should be used.
public lazy var pulseScale: Bool = true
/// The opcaity value for the pulse animation.
public var pulseColorOpacity: CGFloat = 0.25
/// The color of the pulse effect.
public var pulseColor: UIColor?
/**
This property is the same as clipsToBounds. It crops any of the view's This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the the image property, then this value does not need to be set, since the
...@@ -360,7 +412,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -360,7 +412,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
depth = .None depth = .None
cornerRadiusPreset = .None cornerRadiusPreset = .None
shape = .None shape = .None
contentsGravity = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
} }
...@@ -375,7 +427,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -375,7 +427,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
depth = .None depth = .None
cornerRadiusPreset = .None cornerRadiusPreset = .None
shape = .None shape = .None
contentsGravity = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
......
...@@ -76,4 +76,14 @@ public struct MaterialDevice { ...@@ -76,4 +76,14 @@ public struct MaterialDevice {
public static var scale: CGFloat { public static var scale: CGFloat {
return UIScreen.mainScreen().scale return UIScreen.mainScreen().scale
} }
/// Retrieves the device status bar style.
public static var statusBarStyle: UIStatusBarStyle {
get {
return UIApplication.sharedApplication().statusBarStyle
}
set(value) {
UIApplication.sharedApplication().statusBarStyle = value
}
}
} }
\ No newline at end of file
...@@ -143,6 +143,13 @@ public class MaterialLayer : CAShapeLayer { ...@@ -143,6 +143,13 @@ public class MaterialLayer : CAShapeLayer {
} }
} }
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet {
contentsGravity = MaterialGravityToString(contentsGravityPreset)
}
}
/// Determines how content should be aligned within the visualLayer's bounds. /// Determines how content should be aligned within the visualLayer's bounds.
public override var contentsGravity: String { public override var contentsGravity: String {
get { get {
...@@ -236,6 +243,7 @@ public class MaterialLayer : CAShapeLayer { ...@@ -236,6 +243,7 @@ public class MaterialLayer : CAShapeLayer {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareVisualLayer() prepareVisualLayer()
} }
...@@ -246,12 +254,14 @@ public class MaterialLayer : CAShapeLayer { ...@@ -246,12 +254,14 @@ public class MaterialLayer : CAShapeLayer {
- Parameter layer: AnyObject. - Parameter layer: AnyObject.
*/ */
public override init(layer: AnyObject) { public override init(layer: AnyObject) {
contentsGravityPreset = .ResizeAspectFill
super.init() super.init()
prepareVisualLayer() prepareVisualLayer()
} }
/// A convenience initializer. /// A convenience initializer.
public override init() { public override init() {
contentsGravityPreset = .ResizeAspectFill
super.init() super.init()
prepareVisualLayer() prepareVisualLayer()
} }
......
...@@ -63,8 +63,11 @@ public class MaterialView : UIView { ...@@ -63,8 +63,11 @@ public class MaterialView : UIView {
terms of how the image is cropped and stretched. terms of how the image is cropped and stretched.
*/ */
public var contentsRect: CGRect { public var contentsRect: CGRect {
didSet { get {
visualLayer.contentsRect = contentsRect return visualLayer.contentsRect
}
set(value) {
visualLayer.contentsRect = value
} }
} }
...@@ -73,26 +76,42 @@ public class MaterialView : UIView { ...@@ -73,26 +76,42 @@ public class MaterialView : UIView {
with a fixed border around the edge. with a fixed border around the edge.
*/ */
public var contentsCenter: CGRect { public var contentsCenter: CGRect {
didSet { get {
visualLayer.contentsCenter = contentsCenter return visualLayer.contentsCenter
}
set(value) {
visualLayer.contentsCenter = value
} }
} }
/** /**
A floating point value that defines a ratio between the pixel A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the MaterialDevice.scale. of the view. By default, this value is set to the MaterialDevice.scale.
*/ */
public var contentsScale: CGFloat { public var contentsScale: CGFloat {
get {
return visualLayer.contentsScale
}
set(value) {
visualLayer.contentsScale = value
}
}
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet { didSet {
visualLayer.contentsScale = contentsScale contentsGravity = MaterialGravityToString(contentsGravityPreset)
} }
} }
/// Determines how content should be aligned within the visualLayer's bounds. /// Determines how content should be aligned within the visualLayer's bounds.
public var contentsGravity: MaterialGravity { public var contentsGravity: String {
didSet { get {
visualLayer.contentsGravity = MaterialGravityToString(contentsGravity) return visualLayer.contentsGravity
}
set(value) {
visualLayer.contentsGravity = value
} }
} }
...@@ -344,10 +363,7 @@ public class MaterialView : UIView { ...@@ -344,10 +363,7 @@ public class MaterialView : UIView {
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsRect = CGRectMake(0, 0, 1, 1) contentsGravityPreset = .ResizeAspectFill
contentsCenter = CGRectMake(0, 0, 1, 1)
contentsScale = MaterialDevice.scale
contentsGravity = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
} }
...@@ -359,10 +375,7 @@ public class MaterialView : UIView { ...@@ -359,10 +375,7 @@ public class MaterialView : UIView {
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsRect = CGRectMake(0, 0, 1, 1) contentsGravityPreset = .ResizeAspectFill
contentsCenter = CGRectMake(0, 0, 1, 1)
contentsScale = MaterialDevice.scale
contentsGravity = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
......
...@@ -33,9 +33,13 @@ import UIKit ...@@ -33,9 +33,13 @@ import UIKit
/// A memory reference to the Grid instance for UIView extensions. /// A memory reference to the Grid instance for UIView extensions.
private var NavigationBarKey: UInt8 = 0 private var NavigationBarKey: UInt8 = 0
public class Controls { public class NavigationBarControls {
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset public var contentInsetPreset: MaterialEdgeInset {
didSet {
contentInset = MaterialEdgeInsetToValue(contentInsetPreset)
}
}
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets public var contentInset: UIEdgeInsets
...@@ -47,17 +51,17 @@ public class Controls { ...@@ -47,17 +51,17 @@ public class Controls {
public var rightControls: Array<UIControl>? public var rightControls: Array<UIControl>?
public init() { public init() {
contentInsetPreset = .Square3 contentInsetPreset = .Square2
contentInset = MaterialEdgeInsetToValue(.Square3) contentInset = MaterialEdgeInsetToValue(.Square2)
} }
} }
public extension UINavigationBar { public extension UINavigationBar {
/// Controls reference. /// NavigationBarControls reference.
public var controls: Controls { public var controls: NavigationBarControls {
get { get {
return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) { return MaterialObjectAssociatedObject(self, key: &NavigationBarKey) {
return Controls() return NavigationBarControls()
} }
} }
set(value) { set(value) {
...@@ -68,10 +72,10 @@ public extension UINavigationBar { ...@@ -68,10 +72,10 @@ public extension UINavigationBar {
/// Device status bar style. /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle { public var statusBarStyle: UIStatusBarStyle {
get { get {
return UIApplication.sharedApplication().statusBarStyle return MaterialDevice.statusBarStyle
} }
set(value) { set(value) {
UIApplication.sharedApplication().statusBarStyle = value MaterialDevice.statusBarStyle = value
} }
} }
...@@ -83,13 +87,11 @@ public extension UINavigationBar { ...@@ -83,13 +87,11 @@ public extension UINavigationBar {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>() var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value { if let v: Array<UIControl> = value {
for q in v { for q in v {
q.frame.size = CGSizeMake(48, 32)
if let p: UIButton = q as? UIButton { if let p: UIButton = q as? UIButton {
p.frame.size = CGSizeMake(40, 28)
p.contentEdgeInsets = UIEdgeInsetsZero p.contentEdgeInsets = UIEdgeInsetsZero
c.append(UIBarButtonItem(customView: p))
} else {
c.append(UIBarButtonItem(customView: q))
} }
c.append(UIBarButtonItem(customView: q))
} }
} }
...@@ -110,13 +112,11 @@ public extension UINavigationBar { ...@@ -110,13 +112,11 @@ public extension UINavigationBar {
var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>() var c: Array<UIBarButtonItem> = Array<UIBarButtonItem>()
if let v: Array<UIControl> = value { if let v: Array<UIControl> = value {
for q in v { for q in v {
q.frame.size = CGSizeMake(48, 32)
if let p: UIButton = q as? UIButton { if let p: UIButton = q as? UIButton {
p.frame.size = CGSizeMake(40, 28)
p.contentEdgeInsets = UIEdgeInsetsZero p.contentEdgeInsets = UIEdgeInsetsZero
c.append(UIBarButtonItem(customView: p))
} else {
c.append(UIBarButtonItem(customView: q))
} }
c.append(UIBarButtonItem(customView: q))
} }
} }
...@@ -131,23 +131,133 @@ public extension UINavigationBar { ...@@ -131,23 +131,133 @@ public extension UINavigationBar {
} }
public class NavigationBar : UINavigationBar { public class NavigationBar : UINavigationBar {
/**
A CAShapeLayer used to manage elements that would be affected by
the clipToBounds property of the backing layer. For example, this
allows the dropshadow effect on the backing layer, while clipping
the image to a desired shape within the visualLayer.
*/
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
/**
A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
property to avoid conflicts when using clipsToBounds.
*/
public var image: UIImage? {
didSet {
visualLayer.contents = image?.CGImage
}
}
/**
Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows
much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched.
*/
public var contentsRect: CGRect {
get {
return visualLayer.contentsRect
}
set(value) {
visualLayer.contentsRect = value
}
}
/**
A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge.
*/
public var contentsCenter: CGRect {
get {
return visualLayer.contentsCenter
}
set(value) {
visualLayer.contentsCenter = value
}
}
/**
A floating point value that defines a ratio between the pixel
dimensions of the visualLayer's contents property and the size
of the view. By default, this value is set to the MaterialDevice.scale.
*/
public var contentsScale: CGFloat {
get {
return visualLayer.contentsScale
}
set(value) {
visualLayer.contentsScale = value
}
}
/// A Preset for the contentsGravity property.
public var contentsGravityPreset: MaterialGravity {
didSet {
contentsGravity = MaterialGravityToString(contentsGravityPreset)
}
}
/// Determines how content should be aligned within the visualLayer's bounds.
public var contentsGravity: String {
get {
return visualLayer.contentsGravity
}
set(value) {
visualLayer.contentsGravity = value
}
}
/**
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
the image property, then this value does not need to be set, since the
visualLayer's maskToBounds is set to true by default.
*/
public var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set(value) {
layer.masksToBounds = value
}
}
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
public var contentInsetPreset: MaterialEdgeInset { public var contentInsetPreset: MaterialEdgeInset {
get { get {
return controls.contentInsetPreset return grid.contentInsetPreset
} }
set(value) { set(value) {
controls.contentInsetPreset = value grid.contentInsetPreset = value
} }
} }
/// A wrapper around grid.contentInset. /// A wrapper around grid.contentInset.
public var contentInset: UIEdgeInsets { public var contentInset: UIEdgeInsets {
get { get {
return controls.contentInset return grid.contentInset
} }
set(value) { set(value) {
controls.contentInset = value grid.contentInset = value
}
}
/// A preset wrapper around spacing.
public var spacingPreset: MaterialSpacing = .None {
didSet {
spacing = MaterialSpacingToValue(spacingPreset)
}
}
/// A wrapper around grid.spacing.
public var spacing: CGFloat {
get {
return grid.spacing
}
set(value) {
grid.spacing = value
} }
} }
...@@ -172,6 +282,56 @@ public class NavigationBar : UINavigationBar { ...@@ -172,6 +282,56 @@ public class NavigationBar : UINavigationBar {
} }
} }
/// A property that accesses the layer.frame.origin.x property.
public var x: CGFloat {
get {
return layer.frame.origin.x
}
set(value) {
layer.frame.origin.x = value
}
}
/// A property that accesses the layer.frame.origin.y property.
public var y: CGFloat {
get {
return layer.frame.origin.y
}
set(value) {
layer.frame.origin.y = value
}
}
/**
A property that accesses the layer.frame.origin.width property.
When setting this property in conjunction with the shape property having a
value that is not .None, the height will be adjusted to maintain the correct
shape.
*/
public var width: CGFloat {
get {
return layer.frame.size.width
}
set(value) {
layer.frame.size.width = value
}
}
/**
A property that accesses the layer.frame.origin.height property.
When setting this property in conjunction with the shape property having a
value that is not .None, the width will be adjusted to maintain the correct
shape.
*/
public var height: CGFloat {
get {
return layer.frame.size.height
}
set(value) {
layer.frame.size.height = value
}
}
/// A property that accesses the backing layer's shadowColor. /// A property that accesses the backing layer's shadowColor.
public var shadowColor: UIColor? { public var shadowColor: UIColor? {
didSet { didSet {
...@@ -223,7 +383,7 @@ public class NavigationBar : UINavigationBar { ...@@ -223,7 +383,7 @@ public class NavigationBar : UINavigationBar {
public var shadowPathAutoSizeEnabled: Bool = false { public var shadowPathAutoSizeEnabled: Bool = false {
didSet { didSet {
if shadowPathAutoSizeEnabled { if shadowPathAutoSizeEnabled {
// layoutShadowPath() layoutShadowPath()
} else { } else {
shadowPath = nil shadowPath = nil
} }
...@@ -241,16 +401,86 @@ public class NavigationBar : UINavigationBar { ...@@ -241,16 +401,86 @@ public class NavigationBar : UINavigationBar {
shadowOffset = value.offset shadowOffset = value.offset
shadowOpacity = value.opacity shadowOpacity = value.opacity
shadowRadius = value.radius shadowRadius = value.radius
// layoutShadowPath() layoutShadowPath()
}
}
/// A property that sets the cornerRadius of the backing layer.
public var cornerRadiusPreset: MaterialRadius = .None {
didSet {
if let v: MaterialRadius = cornerRadiusPreset {
cornerRadius = MaterialRadiusToValue(v)
}
}
}
/// A property that accesses the layer.cornerRadius.
public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set(value) {
layer.cornerRadius = value
layoutShadowPath()
}
}
/// A preset property to set the borderWidth.
public var borderWidthPreset: MaterialBorder = .None {
didSet {
borderWidth = MaterialBorderToValue(borderWidthPreset)
}
}
/// A property that accesses the layer.borderWith.
public var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set(value) {
layer.borderWidth = value
}
}
/// A property that accesses the layer.borderColor property.
public var borderColor: UIColor? {
get {
return nil == layer.borderColor ? nil : UIColor(CGColor: layer.borderColor!)
}
set(value) {
layer.borderColor = value?.CGColor
}
}
/// A property that accesses the layer.position property.
public var position: CGPoint {
get {
return layer.position
}
set(value) {
layer.position = value
}
}
/// A property that accesses the layer.zPosition property.
public var zPosition: CGFloat {
get {
return layer.zPosition
}
set(value) {
layer.zPosition = value
} }
} }
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
prepareView() prepareView()
} }
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
prepareView() prepareView()
} }
...@@ -261,11 +491,34 @@ public class NavigationBar : UINavigationBar { ...@@ -261,11 +491,34 @@ public class NavigationBar : UINavigationBar {
backButtonImage = nil backButtonImage = nil
backgroundColor = MaterialColor.white backgroundColor = MaterialColor.white
depth = .Depth1 depth = .Depth1
spacingPreset = .Spacing2
contentInsetPreset = .Square2
titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)] titleTextAttributes = [NSFontAttributeName: RobotoFont.regularWithSize(20)]
prepareVisualLayer()
backgroundColor = MaterialColor.white
}
/// Prepares the visualLayer property.
internal func prepareVisualLayer() {
visualLayer.zPosition = 0
visualLayer.masksToBounds = true
layer.addSublayer(visualLayer)
}
/// Manages the layout for the visualLayer property.
internal func layoutVisualLayer() {
visualLayer.frame = bounds
visualLayer.cornerRadius = cornerRadius
} }
public func reloadView() { /// Sets the shadow path.
leftControls = controls.leftControls internal func layoutShadowPath() {
rightControls = controls.rightControls if shadowPathAutoSizeEnabled {
if .None == depth {
shadowPath = nil
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).CGPath
}
}
} }
} }
...@@ -56,11 +56,4 @@ public class NavigationController : UINavigationController { ...@@ -56,11 +56,4 @@ public class NavigationController : UINavigationController {
public func prepareView() { public func prepareView() {
navigationItem.title = "Title" navigationItem.title = "Title"
} }
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if let v: NavigationBar = navigationBar as? NavigationBar {
v.reloadView()
}
}
} }
...@@ -41,9 +41,12 @@ public class StatusBarView : ControlView { ...@@ -41,9 +41,12 @@ public class StatusBarView : ControlView {
public var heightForLandscapeOrientation: CGFloat = 44 public var heightForLandscapeOrientation: CGFloat = 44
/// Device status bar style. /// Device status bar style.
public var statusBarStyle: UIStatusBarStyle = UIApplication.sharedApplication().statusBarStyle { public var statusBarStyle: UIStatusBarStyle {
didSet { get {
UIApplication.sharedApplication().statusBarStyle = statusBarStyle return MaterialDevice.statusBarStyle
}
set(value) {
MaterialDevice.statusBarStyle = value
} }
} }
......
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