Improvements made.
This commit is contained in:
parent
45467c9e3f
commit
6f77c64e16
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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))
|
||||
|
||||
@ -86,5 +86,4 @@ open class DashLine: MFView {
|
||||
dashColor = UIColor.mfGet(forHex: dashColorHex)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user