Improvements made.
This commit is contained in:
parent
45467c9e3f
commit
6f77c64e16
@ -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,12 +72,8 @@ 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)
|
||||||
|
|
||||||
var caretViewIs: UIView? = rightView
|
var caretViewIs: UIView? = rightView
|
||||||
@ -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
|
|
||||||
|
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
|
NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretViewIs, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
|
||||||
|
|
||||||
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
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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))
|
||||||
|
|||||||
@ -86,5 +86,4 @@ open class DashLine: MFView {
|
|||||||
dashColor = UIColor.mfGet(forHex: dashColorHex)
|
dashColor = UIColor.mfGet(forHex: dashColorHex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user