Commit 4309031e by Daniel Dahan

development: added optional divider for all UIViews

parent 1185c534
...@@ -40,7 +40,7 @@ open class Card: PulseView { ...@@ -40,7 +40,7 @@ open class Card: PulseView {
:name: dividerColor :name: dividerColor
*/ */
@IBInspectable @IBInspectable
open var dividerColor: UIColor? { open override var dividerColor: UIColor? {
didSet { didSet {
dividerLayer?.backgroundColor = dividerColor?.cgColor dividerLayer?.backgroundColor = dividerColor?.cgColor
} }
......
...@@ -40,7 +40,7 @@ open class ImageCard: PulseView { ...@@ -40,7 +40,7 @@ open class ImageCard: PulseView {
:name: dividerColor :name: dividerColor
*/ */
@IBInspectable @IBInspectable
open var dividerColor: UIColor? { open override var dividerColor: UIColor? {
didSet { didSet {
dividerLayer?.backgroundColor = dividerColor?.cgColor dividerLayer?.backgroundColor = dividerColor?.cgColor
} }
......
...@@ -30,20 +30,12 @@ ...@@ -30,20 +30,12 @@
import UIKit import UIKit
open class MaterialLayer { internal class MaterialLayer {
/// A reference to the UIView. /// A reference to the CALayer.
internal weak var layer: CALayer? internal weak var layer: CALayer?
/**
Initializer that takes in a UIView.
- Parameter view: A UIView reference.
*/
internal init(layer: CALayer?) {
self.layer = layer
}
/// A property that sets the cornerRadius of the backing layer. /// A property that sets the cornerRadius of the backing layer.
open var cornerRadiusPreset: CornerRadiusPreset = .none { internal var cornerRadiusPreset: CornerRadiusPreset = .none {
didSet { didSet {
guard let v = layer else { guard let v = layer else {
return return
...@@ -53,7 +45,7 @@ open class MaterialLayer { ...@@ -53,7 +45,7 @@ open class MaterialLayer {
} }
/// A preset property to set the borderWidth. /// A preset property to set the borderWidth.
open var borderWidthPreset: BorderWidthPreset = .none { internal var borderWidthPreset: BorderWidthPreset = .none {
didSet { didSet {
guard let v = layer else { guard let v = layer else {
return return
...@@ -63,10 +55,10 @@ open class MaterialLayer { ...@@ -63,10 +55,10 @@ open class MaterialLayer {
} }
/// A preset property to set the shape. /// A preset property to set the shape.
open var shapePreset: ShapePreset = .none internal var shapePreset: ShapePreset = .none
/// A preset value for Depth. /// A preset value for Depth.
open var depthPreset: DepthPreset { internal var depthPreset: DepthPreset {
get { get {
return depth.preset return depth.preset
} }
...@@ -76,7 +68,7 @@ open class MaterialLayer { ...@@ -76,7 +68,7 @@ open class MaterialLayer {
} }
/// Grid reference. /// Grid reference.
open var depth = Depth.zero { internal var depth = Depth.zero {
didSet { didSet {
guard let v = layer else { guard let v = layer else {
return return
...@@ -90,13 +82,21 @@ open class MaterialLayer { ...@@ -90,13 +82,21 @@ open class MaterialLayer {
} }
/// Enables automatic shadowPath sizing. /// Enables automatic shadowPath sizing.
open var isShadowPathAutoSizing = false { internal var isShadowPathAutoSizing = false {
didSet { didSet {
if isShadowPathAutoSizing { if isShadowPathAutoSizing {
layer?.layoutShadowPath() layer?.layoutShadowPath()
} }
} }
} }
/**
Initializer that takes in a CALayer.
- Parameter view: A CALayer reference.
*/
internal init(layer: CALayer?) {
self.layer = layer
}
} }
/// A memory reference to the MaterialLayer instance for CALayer extensions. /// A memory reference to the MaterialLayer instance for CALayer extensions.
...@@ -243,6 +243,16 @@ extension CALayer { ...@@ -243,6 +243,16 @@ extension CALayer {
} }
} }
/// A UIColor reference to the `backgroundColor.cgColor`.
open var color: UIColor? {
get {
return nil == backgroundColor ? nil : UIColor(cgColor: backgroundColor!)
}
set(value) {
backgroundColor = color?.cgColor
}
}
/** /**
A method that accepts CAAnimation objects and executes them on the A method that accepts CAAnimation objects and executes them on the
view's backing layer. view's backing layer.
......
...@@ -30,8 +30,112 @@ ...@@ -30,8 +30,112 @@
import UIKit import UIKit
@objc(DividerAlignment)
public enum DividerAlignment: Int {
case top
case left
case bottom
case right
}
open class MaterialView {
/// A reference to the UIView.
internal weak var view: UIView?
/// A reference to the divider UIView.
internal var divider: UIView?
/// Divider color.
open var dividerColor: UIColor? {
get {
return divider?.backgroundColor
}
set(value) {
guard let v = value else {
divider?.removeFromSuperview()
divider = nil
return
}
if nil == divider {
divider = UIView()
divider?.zPosition = 5000
view?.addSubview(divider!)
layoutDivider()
}
divider?.backgroundColor = v
}
}
/// A reference to the dividerAlignment.
internal var dividerAlignment = DividerAlignment.top {
didSet {
layoutDivider()
}
}
/**
Initializer that takes in a UIView.
- Parameter view: A UIView reference.
*/
internal init(view: UIView?) {
self.view = view
}
/// Lays out the divider.
internal func layoutDivider() {
guard let v = view else {
return
}
guard let d = divider else {
return
}
switch dividerAlignment {
case .top:
d.frame = CGRect(x: 0, y: 0, width: v.width, height: 1)
case .bottom:
d.frame = CGRect(x: 0, y: v.height - 1, width: v.width, height: 1)
case .left:
d.frame = CGRect(x: 0, y: 0, width: 1, height: v.height)
case .right:
d.frame = CGRect(x: v.width - 1, y: 0, width: 1, height: v.height)
}
}
}
/// A memory reference to the MaterialView instance for UIView extensions.
private var MaterialViewKey: UInt8 = 0
/// Grid extension for UIView. /// Grid extension for UIView.
extension UIView { extension UIView {
/// Layer Reference.
internal var materialView: MaterialView {
get {
return AssociatedObject(base: self, key: &MaterialViewKey) {
return MaterialView(view: self)
}
}
set(value) {
AssociateObject(base: self, key: &MaterialViewKey, value: value)
}
}
/// Divider color.
open var dividerColor: UIColor? {
get {
return materialView.dividerColor
}
set(value) {
materialView.dividerColor = value
}
}
/// Divider alignment.
open var dividerAlignment: DividerAlignment {
return materialView.dividerAlignment
}
/// A property that accesses the frame.origin.x property. /// A property that accesses the frame.origin.x property.
@IBInspectable @IBInspectable
open var x: CGFloat { open var x: CGFloat {
...@@ -288,4 +392,9 @@ extension UIView { ...@@ -288,4 +392,9 @@ extension UIView {
open func layoutShadowPath() { open func layoutShadowPath() {
layer.layoutShadowPath() layer.layoutShadowPath()
} }
/// Lays out the divider.
open func layoutDivider() {
materialView.layoutDivider()
}
} }
...@@ -36,6 +36,18 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate { ...@@ -36,6 +36,18 @@ open class PhotoLibraryController: UIViewController, PhotoLibraryDelegate {
open override func viewDidLoad() { open override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView()
}
/**
Prepares the view instance when intialized. When subclassing,
it is recommended to override the prepareView method
to initialize property values and other setup operations.
The super.prepareView method should always be called immediately
when subclassing.
*/
open func prepareView() {
view.contentScaleFactor = Device.scale
preparePhotoLibrary() preparePhotoLibrary()
} }
......
...@@ -37,9 +37,9 @@ public enum TabBarLineAlignment: Int { ...@@ -37,9 +37,9 @@ public enum TabBarLineAlignment: Int {
} }
open class TabBar: View { open class TabBar: View {
/// A reference to the line UIView. /// A reference to the line UIView.
open internal(set) var line: UIView! open internal(set) var line: UIView!
/// A value for the line alignment. /// A value for the line alignment.
open var lineAlignment = TabBarLineAlignment.bottom { open var lineAlignment = TabBarLineAlignment.bottom {
didSet { didSet {
...@@ -92,7 +92,7 @@ open class TabBar: View { ...@@ -92,7 +92,7 @@ open class TabBar: View {
} }
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
return CGSize(width: width, height: 44) return CGSize(width: width, height: 49)
} }
/// Buttons. /// Buttons.
...@@ -109,7 +109,7 @@ open class TabBar: View { ...@@ -109,7 +109,7 @@ open class TabBar: View {
layoutSubviews() layoutSubviews()
} }
} }
open override func layoutSubviews() { open override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
...@@ -125,6 +125,7 @@ open class TabBar: View { ...@@ -125,6 +125,7 @@ open class TabBar: View {
grid.views = buttons as [UIView] grid.views = buttons as [UIView]
line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: buttons.first!.width, height: 3) line.frame = CGRect(x: 0, y: .bottom == lineAlignment ? height - 3 : 0, width: buttons.first!.width, height: 3)
} }
layoutDivider()
} }
} }
......
...@@ -63,10 +63,10 @@ open class TextField: UITextField { ...@@ -63,10 +63,10 @@ open class TextField: UITextField {
/// Sets the divider. /// Sets the divider.
@IBInspectable @IBInspectable
open var dividerColor = Color.darkText.dividers { open override var dividerColor: UIColor? {
didSet { didSet {
if !isEditing { if !isEditing {
divider.backgroundColor = dividerColor.cgColor divider.backgroundColor = dividerColor?.cgColor
} }
} }
} }
...@@ -384,7 +384,7 @@ open class TextField: UITextField { ...@@ -384,7 +384,7 @@ open class TextField: UITextField {
} }
/// Layout the divider. /// Layout the divider.
open func layoutDivider() { open override func layoutDivider() {
divider.frame = CGRect(x: 0, y: height, width: width, height: isEditing ? dividerActiveHeight : dividerHeight) divider.frame = CGRect(x: 0, y: height, width: width, height: isEditing ? dividerActiveHeight : dividerHeight)
} }
...@@ -451,7 +451,7 @@ open class TextField: UITextField { ...@@ -451,7 +451,7 @@ open class TextField: UITextField {
/// The animation for the divider when editing ends. /// The animation for the divider when editing ends.
open func dividerEditingDidEndAnimation() { open func dividerEditingDidEndAnimation() {
divider.frame.size.height = dividerHeight divider.frame.size.height = dividerHeight
divider.backgroundColor = dividerColor.cgColor divider.backgroundColor = dividerColor?.cgColor
} }
/// The animation for the placeholder when editing begins. /// The animation for the placeholder when editing begins.
......
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