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()
} }
......
...@@ -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