Improvements made.

This commit is contained in:
Christiano, Kevin 2019-03-26 16:40:23 -04:00
parent 45467c9e3f
commit 6f77c64e16
3 changed files with 19 additions and 53 deletions

View File

@ -13,8 +13,8 @@ open class CaretButton: MFCustomButton {
// MARK: - Constants // MARK: - Constants
//------------------------------------------------------ //------------------------------------------------------
private let CaretViewHeight: CGFloat = 10.8 private let CaretViewHeight: Float = 10.8
private let CaretViewWidth: CGFloat = 6.6 private let CaretViewWidth: Float = 6.6
//------------------------------------------------------ //------------------------------------------------------
// MARK: - Properties // MARK: - Properties
@ -72,11 +72,7 @@ open class CaretButton: MFCustomButton {
rightView?.removeFromSuperview() rightView?.removeFromSuperview()
let edgeInsets: UIEdgeInsets = contentEdgeInsets let edgeInsets: UIEdgeInsets = contentEdgeInsets
var rightInset: CGFloat = CaretViewWidth let rightInset = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth)
if let rightFloatValue = rightViewWidth?.floatValue {
rightInset = CGFloat(rightFloatValue)
}
contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + rightInset) contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + rightInset)
@ -87,49 +83,28 @@ open class CaretButton: MFCustomButton {
} }
rightView?.translatesAutoresizingMaskIntoConstraints = false rightView?.translatesAutoresizingMaskIntoConstraints = false
if let right = rightView { if let right = rightView {
addSubview(right) addSubview(right)
} }
var width: CGFloat = CaretViewWidth let width = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth)
if let rightFloatValue = rightViewWidth?.floatValue {
width = CGFloat(rightFloatValue)
}
var caretViewWidthConstraint: NSLayoutConstraint?
if let caretViewIs = caretViewIs { if let caretViewIs = caretViewIs {
caretViewWidthConstraint = NSLayoutConstraint(item: caretViewIs, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width) NSLayoutConstraint(item: caretViewIs, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width).isActive = true
caretViewWidthConstraint?.isActive = true
}
var height: CGFloat = CaretViewHeight let height = CGFloat(rightViewHeight?.floatValue ?? CaretViewHeight)
if let rightHeight = rightViewHeight?.floatValue { NSLayoutConstraint(item: caretViewIs, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height).isActive = true
height = CGFloat(rightHeight)
}
var caretViewHeightConstraint: NSLayoutConstraint? let caretLabelSpacing = NSLayoutConstraint(item: caretViewIs, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0)
if let caretViewIs = caretViewIs { caretLabelSpacing.isActive = true
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 caretSpacingConstraint = caretLabelSpacing
var caretCenterY: NSLayoutConstraint? NSLayoutConstraint(item: caretViewIs, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true
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) NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretViewIs, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
caretLabelRightPin.isActive = true
contentHorizontalAlignment = .left contentHorizontalAlignment = .left
//set correct color after layout //set correct color after layout
changeCaretColor() changeCaretColor()
@ -167,7 +142,5 @@ open class CaretButton: MFCustomButton {
if let disabledColorHex = jsonDictionary["disabledColor"] as? String { if let disabledColorHex = jsonDictionary["disabledColor"] as? String {
disabledColor = UIColor.mfGet(forHex: disabledColorHex) disabledColor = UIColor.mfGet(forHex: disabledColorHex)
} }
} }
} }

View File

@ -64,13 +64,7 @@ open class CaretView: MFView {
let context = UIGraphicsGetCurrentContext() let context = UIGraphicsGetCurrentContext()
context?.clear(rect) context?.clear(rect)
var lineWidthToDraw: CGFloat = 0.0 let lineWidthToDraw: CGFloat = lineWidth ?? frame.size.width / 2.6
if let width = lineWidth {
lineWidthToDraw = width
} else {
lineWidthToDraw = frame.size.width / 2.6
}
let path = UIBezierPath() let path = UIBezierPath()
path.move(to: CGPoint(x: lineWidthToDraw / 2.0, y: 0.0)) path.move(to: CGPoint(x: lineWidthToDraw / 2.0, y: 0.0))

View File

@ -86,5 +86,4 @@ open class DashLine: MFView {
dashColor = UIColor.mfGet(forHex: dashColorHex) dashColor = UIColor.mfGet(forHex: dashColorHex)
} }
} }
} }