From 6f77c64e16899461f13c081ef5224adf3d6c0435 Mon Sep 17 00:00:00 2001 From: "Christiano, Kevin" Date: Tue, 26 Mar 2019 16:40:23 -0400 Subject: [PATCH] Improvements made. --- MVMCoreUI/Atoms/Buttons/CaretButton.swift | 63 +++++++---------------- MVMCoreUI/Atoms/Views/CaretView.swift | 8 +-- MVMCoreUI/Atoms/Views/DashLine.swift | 1 - 3 files changed, 19 insertions(+), 53 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/CaretButton.swift b/MVMCoreUI/Atoms/Buttons/CaretButton.swift index 95a7e37f..393821e8 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretButton.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretButton.swift @@ -13,8 +13,8 @@ open class CaretButton: MFCustomButton { // MARK: - Constants //------------------------------------------------------ - private let CaretViewHeight: CGFloat = 10.8 - private let CaretViewWidth: CGFloat = 6.6 + private let CaretViewHeight: Float = 10.8 + private let CaretViewWidth: Float = 6.6 //------------------------------------------------------ // MARK: - Properties @@ -72,12 +72,8 @@ open class CaretButton: MFCustomButton { rightView?.removeFromSuperview() let edgeInsets: UIEdgeInsets = contentEdgeInsets - var rightInset: CGFloat = CaretViewWidth - - if let rightFloatValue = rightViewWidth?.floatValue { - rightInset = CGFloat(rightFloatValue) - } - + let rightInset = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth) + contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + rightInset) var caretViewIs: UIView? = rightView @@ -87,49 +83,28 @@ open class CaretButton: MFCustomButton { } rightView?.translatesAutoresizingMaskIntoConstraints = false + if let right = rightView { addSubview(right) } - var width: CGFloat = CaretViewWidth - if let rightFloatValue = rightViewWidth?.floatValue { - width = CGFloat(rightFloatValue) - } - - var caretViewWidthConstraint: NSLayoutConstraint? + let width = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth) if let caretViewIs = caretViewIs { - caretViewWidthConstraint = NSLayoutConstraint(item: caretViewIs, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width) - caretViewWidthConstraint?.isActive = true + NSLayoutConstraint(item: caretViewIs, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width).isActive = true + + let height = CGFloat(rightViewHeight?.floatValue ?? CaretViewHeight) + + NSLayoutConstraint(item: caretViewIs, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height).isActive = true + + let caretLabelSpacing = NSLayoutConstraint(item: caretViewIs, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0) + caretLabelSpacing.isActive = true + caretSpacingConstraint = caretLabelSpacing + + NSLayoutConstraint(item: caretViewIs, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true } - var height: CGFloat = CaretViewHeight - - if let rightHeight = rightViewHeight?.floatValue { - height = CGFloat(rightHeight) - } - - var caretViewHeightConstraint: NSLayoutConstraint? - if let caretViewIs = caretViewIs { - caretViewHeightConstraint = NSLayoutConstraint(item: caretViewIs, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height) - caretViewHeightConstraint?.isActive = true - } - - var caretLabelSpacing: NSLayoutConstraint? - if let caretViewIs = caretViewIs { - caretLabelSpacing = NSLayoutConstraint(item: caretViewIs, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0) - caretLabelSpacing?.isActive = true - } - caretSpacingConstraint = caretLabelSpacing - - var caretCenterY: NSLayoutConstraint? - if let caretViewIs = caretViewIs { - caretCenterY = NSLayoutConstraint(item: caretViewIs, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0) - caretCenterY?.isActive = true - } - - let caretLabelRightPin = NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretViewIs, attribute: .right, multiplier: 1.0, constant: 0) - caretLabelRightPin.isActive = true + NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretViewIs, attribute: .right, multiplier: 1.0, constant: 0).isActive = true contentHorizontalAlignment = .left //set correct color after layout changeCaretColor() @@ -167,7 +142,5 @@ open class CaretButton: MFCustomButton { if let disabledColorHex = jsonDictionary["disabledColor"] as? String { disabledColor = UIColor.mfGet(forHex: disabledColorHex) } - } - } diff --git a/MVMCoreUI/Atoms/Views/CaretView.swift b/MVMCoreUI/Atoms/Views/CaretView.swift index b8693457..63267ec6 100644 --- a/MVMCoreUI/Atoms/Views/CaretView.swift +++ b/MVMCoreUI/Atoms/Views/CaretView.swift @@ -64,13 +64,7 @@ open class CaretView: MFView { let context = UIGraphicsGetCurrentContext() context?.clear(rect) - var lineWidthToDraw: CGFloat = 0.0 - - if let width = lineWidth { - lineWidthToDraw = width - } else { - lineWidthToDraw = frame.size.width / 2.6 - } + let lineWidthToDraw: CGFloat = lineWidth ?? frame.size.width / 2.6 let path = UIBezierPath() path.move(to: CGPoint(x: lineWidthToDraw / 2.0, y: 0.0)) diff --git a/MVMCoreUI/Atoms/Views/DashLine.swift b/MVMCoreUI/Atoms/Views/DashLine.swift index 21ec35af..9b3e7f52 100644 --- a/MVMCoreUI/Atoms/Views/DashLine.swift +++ b/MVMCoreUI/Atoms/Views/DashLine.swift @@ -86,5 +86,4 @@ open class DashLine: MFView { dashColor = UIColor.mfGet(forHex: dashColorHex) } } - }