Commit 159165b9 by Daniel Dahan

development: added a Divider object to a CollectionViewCell

parent 53a2c6ce
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
@IBDesignable @IBDesignable
open class CollectionView: UICollectionView { open class CollectionView: UICollectionView {
/// A preset wrapper around contentInset. /// A preset wrapper around contentInset.
open var contentEdgeInsetsPreset: EdgeInsets { open var contentEdgeInsetsPreset: EdgeInsets {
get { get {
return (collectionViewLayout as? CollectionViewLayout)!.contentInset return (collectionViewLayout as? CollectionViewLayout)!.contentInset
...@@ -121,6 +121,6 @@ open class CollectionView: UICollectionView { ...@@ -121,6 +121,6 @@ open class CollectionView: UICollectionView {
open func prepareView() { open func prepareView() {
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
backgroundColor = Color.clear backgroundColor = Color.clear
contentInset = UIEdgeInsets.zero contentInset = .zero
} }
} }
...@@ -33,12 +33,15 @@ import UIKit ...@@ -33,12 +33,15 @@ import UIKit
@IBDesignable @IBDesignable
@objc(CollectionViewCell) @objc(CollectionViewCell)
open class CollectionViewCell: UICollectionViewCell { open class CollectionViewCell: UICollectionViewCell {
/** /// A reference to the divider.
A CAShapeLayer used to manage elements that would be affected by open internal(set) var divider: Divider!
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. 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.
*/
open private(set) var visualLayer: CAShapeLayer! open private(set) var visualLayer: CAShapeLayer!
/// An Array of pulse layers. /// An Array of pulse layers.
...@@ -54,10 +57,10 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -54,10 +57,10 @@ open class CollectionViewCell: UICollectionViewCell {
open var pulseAnimation = PulseAnimation.pointWithBacking open var pulseAnimation = PulseAnimation.pointWithBacking
/** /**
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.
*/ */
@IBInspectable @IBInspectable
open var image: UIImage? { open var image: UIImage? {
didSet { didSet {
...@@ -66,11 +69,11 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -66,11 +69,11 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/** /**
Allows a relative subrectangle within the range of 0 to 1 to be Allows a relative subrectangle within the range of 0 to 1 to be
specified for the visualLayer's contents property. This allows specified for the visualLayer's contents property. This allows
much greater flexibility than the contentsGravity property in much greater flexibility than the contentsGravity property in
terms of how the image is cropped and stretched. terms of how the image is cropped and stretched.
*/ */
@IBInspectable @IBInspectable
open var contentsRect: CGRect { open var contentsRect: CGRect {
get { get {
...@@ -82,9 +85,9 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -82,9 +85,9 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/** /**
A CGRect that defines a stretchable region inside the visualLayer A CGRect that defines a stretchable region inside the visualLayer
with a fixed border around the edge. with a fixed border around the edge.
*/ */
@IBInspectable @IBInspectable
open var contentsCenter: CGRect { open var contentsCenter: CGRect {
get { get {
...@@ -96,10 +99,10 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -96,10 +99,10 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/** /**
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 Device.scale. of the view. By default, this value is set to the Device.scale.
*/ */
@IBInspectable @IBInspectable
open var contentsScale: CGFloat { open var contentsScale: CGFloat {
get { get {
...@@ -176,9 +179,9 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -176,9 +179,9 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/** /**
An initializer that initializes the object with a NSCoder object. An initializer that initializes the object with a NSCoder object.
- Parameter aDecoder: A NSCoder instance. - Parameter aDecoder: A NSCoder instance.
*/ */
public required init?(coder aDecoder: NSCoder) { public required init?(coder aDecoder: NSCoder) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(coder: aDecoder) super.init(coder: aDecoder)
...@@ -186,11 +189,11 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -186,11 +189,11 @@ open class CollectionViewCell: UICollectionViewCell {
} }
/** /**
An initializer that initializes the object with a CGRect object. An initializer that initializes the object with a CGRect object.
If AutoLayout is used, it is better to initilize the instance If AutoLayout is used, it is better to initilize the instance
using the init() initializer. using the init() initializer.
- Parameter frame: A CGRect instance. - Parameter frame: A CGRect instance.
*/ */
public override init(frame: CGRect) { public override init(frame: CGRect) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init(frame: frame) super.init(frame: frame)
...@@ -274,6 +277,7 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -274,6 +277,7 @@ open class CollectionViewCell: UICollectionViewCell {
open func prepareView() { open func prepareView() {
contentScaleFactor = Device.scale contentScaleFactor = Device.scale
prepareVisualLayer() prepareVisualLayer()
prepareDivider()
} }
/// Prepares the visualLayer property. /// Prepares the visualLayer property.
...@@ -289,4 +293,9 @@ open class CollectionViewCell: UICollectionViewCell { ...@@ -289,4 +293,9 @@ open class CollectionViewCell: UICollectionViewCell {
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.cornerRadius = cornerRadius visualLayer.cornerRadius = cornerRadius
} }
/// Prepares the divider.
private func prepareDivider() {
divider = Divider(view: self)
}
} }
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