Commit 8e4bfc89 by Daniel Dahan

development: fix for Button convenience initializers and code style updates

parent f3408e13
......@@ -63,7 +63,7 @@ open class BottomTabBar: UITabBar {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
public required init?(coder aDecoder: NSCoder) {
......
......@@ -58,7 +58,7 @@ open class Button: UIButton {
open var pulseColor = Color.grey.base
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .pointWithBacking
public var pulseAnimation = PulseAnimation.pointWithBacking
/// A property that accesses the backing layer's backgroundColor.
@IBInspectable
......@@ -69,7 +69,7 @@ open class Button: UIButton {
}
/// A preset property for updated contentEdgeInsets.
open var contentEdgeInsetsPreset: EdgeInsetsPreset = .none {
open var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet {
contentEdgeInsets = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
}
......@@ -124,7 +124,7 @@ open class Button: UIButton {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
/**
......@@ -133,7 +133,7 @@ open class Button: UIButton {
*/
public convenience init(image: UIImage?) {
self.init()
self.image = image
prepareWith(image: image, tintColor: nil)
}
/**
......@@ -143,8 +143,7 @@ open class Button: UIButton {
*/
public convenience init(image: UIImage?, tintColor: UIColor?) {
self.init()
self.image = image
self.tintColor = tintColor
prepareWith(image: image, tintColor: tintColor)
}
/**
......@@ -153,7 +152,7 @@ open class Button: UIButton {
*/
public convenience init(title: String?) {
self.init()
self.title = title
prepareWith(title: title, titleColor: nil)
}
/**
......@@ -163,8 +162,7 @@ open class Button: UIButton {
*/
public convenience init(title: String?, titleColor: UIColor?) {
self.init()
self.title = title
self.titleColor = titleColor
prepareWith(title: title, titleColor: titleColor)
}
open override func layoutSublayers(of layer: CALayer) {
......@@ -255,4 +253,24 @@ open class Button: UIButton {
visualLayer.frame = bounds
visualLayer.cornerRadius = cornerRadius
}
/**
Prepares the Button with an image and tintColor.
- Parameter image: A UIImage.
- Parameter tintColor: A UIColor.
*/
private func prepareWith(image: UIImage?, tintColor: UIColor?) {
self.image = image
self.tintColor = tintColor
}
/**
Prepares the Button with a title and titleColor.
- Parameter title: A String.
- Parameter titleColor: A UIColor.
*/
private func prepareWith(title: String?, titleColor: UIColor?) {
self.title = title
self.titleColor = titleColor
}
}
......@@ -283,7 +283,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
open override func layoutSubviews() {
......
......@@ -225,14 +225,14 @@ open class Card: PulseView {
:name: init
*/
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
/**
:name: init
*/
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: [UIButton]? = nil, rightButtons: [UIButton]? = nil) {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
}
......
......@@ -194,7 +194,7 @@ open class MaterialCollectionReusableView: UICollectionReusableView {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
open override func layoutSublayers(of layer: CALayer) {
......
......@@ -108,7 +108,7 @@ open class CollectionView: UICollectionView {
/// A convenience initializer that initializes the object.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
/**
......
......@@ -204,7 +204,7 @@ open class CollectionViewCell: UICollectionViewCell {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
open override func layoutSublayers(of layer: CALayer) {
......
......@@ -144,7 +144,7 @@ open class ControlView: View {
public init() {
leftControls = []
rightControls = []
super.init(frame: CGRect.zero)
super.init(frame: .zero)
frame.size = intrinsicContentSize
}
......@@ -156,7 +156,7 @@ open class ControlView: View {
public init(leftControls: [UIView]? = nil, rightControls: [UIView]? = nil) {
self.leftControls = leftControls ?? []
self.rightControls = rightControls ?? []
super.init(frame: CGRect.zero)
super.init(frame: .zero)
frame.size = intrinsicContentSize
}
......@@ -176,8 +176,8 @@ open class ControlView: View {
// leftControls
for c in leftControls {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
......@@ -194,8 +194,8 @@ open class ControlView: View {
// rightControls
for c in rightControls {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
......
......@@ -94,7 +94,7 @@ public struct Depth {
public func DepthPresetToValue(preset: DepthPreset) -> Depth {
switch preset {
case .none:
return Depth.zero
return .zero
case .depth1:
return Depth(offset: Offset(horizontal: 0, vertical: 1), opacity: 0.3, radius: 1)
case .depth2:
......
......@@ -74,7 +74,7 @@ public typealias EdgeInsets = UIEdgeInsets
public func EdgeInsetsPresetToValue(preset: EdgeInsetsPreset) -> EdgeInsets {
switch preset {
case .none:
return EdgeInsets.zero
return .zero
// square
case .square1:
......
......@@ -93,15 +93,15 @@ open class ImageCard: PulseView {
prepareImageLayer()
imageLayer?.contents = v.cgImage
if 0 == maxImageHeight {
imageLayer?.frame.size.height = image!.size.height / contentsScale
imageLayer?.height = image!.height / contentsScale
} else {
let h: CGFloat = image!.size.height / contentsScale
imageLayer?.frame.size.height = maxImageHeight < h ? maxImageHeight : h
let h: CGFloat = image!.height / contentsScale
imageLayer?.height = maxImageHeight < h ? maxImageHeight : h
}
imageLayer?.isHidden = false
} else {
imageLayer?.contents = nil
imageLayer?.frame = CGRect.zero
imageLayer?.frame = .zero
imageLayer?.isHidden = true
imageLayer?.removeFromSuperlayer()
}
......@@ -325,14 +325,14 @@ open class ImageCard: PulseView {
:name: init
*/
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
/**
:name: init
*/
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: [UIButton]? = nil, rightButtons: [UIButton]? = nil) {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
}
......
......@@ -137,7 +137,7 @@ open class Label: UILabel {
:name: init
*/
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
/**
......
......@@ -149,7 +149,7 @@ public class MaterialTextLayer: CATextLayer {
*/
public func stringSize(constrainedToWidth width: Double) -> CGSize {
guard let v = fontType, let t = text, 0 < t.utf16.count else {
return CGSize.zero
return .zero
}
return v.stringSize(string: text!, constrainedToWidth: width)
}
......
......@@ -98,7 +98,7 @@ public class Menu {
/// Convenience initializer.
public convenience init() {
self.init(origin: CGPoint.zero)
self.init(origin: .zero)
}
/// Reload the view layout.
......
......@@ -33,9 +33,9 @@ import UIKit
/// NavigationBar styles.
@objc(NavigationBarStyle)
public enum NavigationBarStyle: Int {
case Tiny
case Default
case Medium
case small
case medium
case large
}
extension UINavigationBar {
......@@ -54,17 +54,17 @@ extension UINavigationBar {
public class NavigationBar: UINavigationBar {
public override var intrinsicContentSize: CGSize {
switch navigationBarStyle {
case .Tiny:
case .small:
return CGSize(width: Device.width, height: 32)
case .Default:
case .medium:
return CGSize(width: Device.width, height: 44)
case .Medium:
case .large:
return CGSize(width: Device.width, height: 56)
}
}
/// NavigationBarStyle value.
public var navigationBarStyle: NavigationBarStyle = .Default
public var navigationBarStyle = NavigationBarStyle.medium
internal var animating: Bool = false
......@@ -74,21 +74,21 @@ public class NavigationBar: UINavigationBar {
}
/// A preset wrapper around contentInset.
public var contentEdgeInsetsPreset: EdgeInsetsPreset = .none {
public var contentEdgeInsetsPreset = EdgeInsetsPreset.none {
didSet {
contentInset = EdgeInsetsPresetToValue(preset: contentEdgeInsetsPreset)
}
}
/// A wrapper around grid.contentInset.
@IBInspectable public var contentInset: EdgeInsets = EdgeInsets.zero {
@IBInspectable public var contentInset = EdgeInsets.zero {
didSet {
layoutSubviews()
}
}
/// A preset wrapper around interimSpace.
public var interimSpacePreset: InterimSpacePreset = .none {
public var interimSpacePreset = InterimSpacePreset.none {
didSet {
interimSpace = InterimSpacePresetToValue(preset: interimSpacePreset)
}
......@@ -153,7 +153,7 @@ public class NavigationBar: UINavigationBar {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
public override func sizeThatFits(_ size: CGSize) -> CGSize {
......@@ -199,7 +199,7 @@ public class NavigationBar: UINavigationBar {
let g = Int(width / gridFactor)
let columns = g + 1
titleView.frame.origin = CGPoint.zero
titleView.frame.origin = .zero
titleView.frame.size = intrinsicContentSize
titleView.grid.views = []
titleView.grid.axis.columns = columns
......@@ -210,8 +210,8 @@ public class NavigationBar: UINavigationBar {
if let v = item.leftControls {
for c in v {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = titleView.height - contentInset.top - contentInset.bottom
c.grid.columns = Int(w / gridFactor) + 1
......@@ -229,8 +229,8 @@ public class NavigationBar: UINavigationBar {
if let v = item.rightControls {
for c in v {
let w = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
(c as? UIButton)?.contentEdgeInsets = .zero
c.height = titleView.height - contentInset.top - contentInset.bottom
c.grid.columns = Int(w / gridFactor) + 1
......@@ -320,7 +320,7 @@ public class NavigationBar: UINavigationBar {
*/
private func prepareTitleView(item: UINavigationItem) -> UIView {
if nil == item.titleView {
item.titleView = UIView(frame: CGRect.zero)
item.titleView = UIView(frame: .zero)
}
return item.titleView!
}
......@@ -332,7 +332,7 @@ public class NavigationBar: UINavigationBar {
*/
private func prepareContentView(item: UINavigationItem) -> UIView {
if nil == item.contentView {
item.contentView = UIView(frame: CGRect.zero)
item.contentView = UIView(frame: .zero)
}
item.contentView!.grid.axis.direction = .vertical
return item.contentView!
......
......@@ -160,7 +160,7 @@ public class SearchBar: BarView {
/// Prepares the clearButton.
private func prepareClearButton() {
clearButton = IconButton(image: Icon.cm.close, tintColor: placeholderColor)
clearButton.contentEdgeInsets = UIEdgeInsets.zero
clearButton.contentEdgeInsets = .zero
clearButtonAutoHandleEnabled = true
textField.clearButtonMode = .never
textField.rightViewMode = .whileEditing
......
......@@ -121,7 +121,7 @@ open class TabBar: View {
let columns: Int = grid.axis.columns / v.count
for b in v {
b.grid.columns = columns
b.contentEdgeInsets = UIEdgeInsets.zero
b.contentEdgeInsets = .zero
b.layer.cornerRadius = 0
b.removeTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
b.addTarget(self, action: #selector(handleButton(button:)), for: .touchUpInside)
......
......@@ -155,7 +155,7 @@ open class TableViewCell: UITableViewCell {
*/
open func prepareView() {
selectionStyle = .none
separatorInset = UIEdgeInsets.zero
separatorInset = .zero
contentScaleFactor = Device.scale
imageView?.isUserInteractionEnabled = false
textLabel?.isUserInteractionEnabled = false
......
......@@ -149,7 +149,7 @@ open class TextField: UITextField {
/// The detailLabel UILabel that is displayed.
@IBInspectable
open private(set) lazy var detailLabel = UILabel(frame: CGRect.zero)
open private(set) lazy var detailLabel = UILabel(frame: .zero)
/// The detailLabel text value.
......@@ -207,7 +207,7 @@ open class TextField: UITextField {
if value {
if nil == clearIconButton {
clearIconButton = IconButton(image: Icon.cm.clear, tintColor: placeholderColor)
clearIconButton!.contentEdgeInsets = UIEdgeInsets.zero
clearIconButton!.contentEdgeInsets = .zero
clearIconButton!.pulseAnimation = .center
clearButtonMode = .never
rightViewMode = .whileEditing
......@@ -242,7 +242,7 @@ open class TextField: UITextField {
if value {
if nil == visibilityIconButton {
visibilityIconButton = IconButton(image: Icon.visibility, tintColor: placeholderColor.withAlphaComponent(isSecureTextEntry ? 0.38 : 0.54))
visibilityIconButton!.contentEdgeInsets = UIEdgeInsets.zero
visibilityIconButton!.contentEdgeInsets = .zero
visibilityIconButton!.pulseAnimation = .center
isSecureTextEntry = true
clearButtonMode = .never
......@@ -296,7 +296,7 @@ open class TextField: UITextField {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
open override func layoutSubviews() {
......@@ -497,7 +497,7 @@ open class TextField: UITextField {
/// Prepares the placeholderLabel.
private func preparePlaceholderLabel() {
placeholderLabel = UILabel(frame: CGRect.zero)
placeholderLabel = UILabel(frame: .zero)
placeholderColor = Color.darkText.others
font = RobotoFont.regularWithSize(size: 16)
addSubview(placeholderLabel)
......
......@@ -134,7 +134,7 @@ public class TextView: UITextView {
- Parameter textContainer: A NSTextContainer instance.
*/
public convenience init(textContainer: NSTextContainer?) {
self.init(frame: CGRect.zero, textContainer: textContainer)
self.init(frame: .zero, textContainer: textContainer)
}
/** Denitializer. This should never be called unless you know
......@@ -218,7 +218,7 @@ public class TextView: UITextView {
*/
public func prepareView() {
contentScaleFactor = Device.scale
textContainerInset = EdgeInsets.zero
textContainerInset = .zero
backgroundColor = Color.white
clipsToBounds = false
removeNotificationHandlers()
......
......@@ -152,7 +152,7 @@ open class View: UIView {
/// A convenience initializer.
public convenience init() {
self.init(frame: CGRect.zero)
self.init(frame: .zero)
}
open override func layoutSublayers(of layer: CALayer) {
......
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