Returned addCaretImageView() to the golden path.
This commit is contained in:
parent
f154befabf
commit
42e482d727
@ -61,7 +61,7 @@ open class CaretButton: MFCustomButton {
|
||||
//------------------------------------------------------
|
||||
|
||||
private func changeCaretColor() {
|
||||
|
||||
|
||||
if let rightCaretView = rightView as? CaretView {
|
||||
rightCaretView.tintColor = isEnabled ? enabledColor : disabledColor
|
||||
}
|
||||
@ -70,41 +70,27 @@ open class CaretButton: MFCustomButton {
|
||||
private func addCaretImageView() {
|
||||
|
||||
rightView?.removeFromSuperview()
|
||||
let edgeInsets: UIEdgeInsets = contentEdgeInsets
|
||||
|
||||
let rightInset = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth)
|
||||
|
||||
contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + rightInset)
|
||||
|
||||
var caretViewIs: UIView? = rightView
|
||||
if rightView == nil {
|
||||
caretViewIs = CaretView()
|
||||
rightView = caretViewIs
|
||||
}
|
||||
|
||||
rightView?.translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
if let right = rightView {
|
||||
addSubview(right)
|
||||
}
|
||||
|
||||
let width = CGFloat(rightViewWidth?.floatValue ?? CaretViewWidth)
|
||||
let height = CGFloat(rightViewHeight?.floatValue ?? CaretViewHeight)
|
||||
|
||||
if let caretViewIs = caretViewIs {
|
||||
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
|
||||
}
|
||||
let edgeInsets: UIEdgeInsets = contentEdgeInsets
|
||||
contentEdgeInsets = UIEdgeInsets(top: edgeInsets.top, left: edgeInsets.left, bottom: edgeInsets.bottom, right: 4 + width)
|
||||
|
||||
NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretViewIs, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
|
||||
let caretView: UIView = rightView ?? CaretView()
|
||||
rightView = caretView
|
||||
rightView?.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(caretView)
|
||||
|
||||
NSLayoutConstraint(item: caretView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: width).isActive = true
|
||||
NSLayoutConstraint(item: caretView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: height).isActive = true
|
||||
|
||||
let caretLabelSpacing = NSLayoutConstraint(item: caretView, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 4.0)
|
||||
caretLabelSpacing.isActive = true
|
||||
caretSpacingConstraint = caretLabelSpacing
|
||||
|
||||
NSLayoutConstraint(item: caretView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true
|
||||
NSLayoutConstraint(item: self, attribute: .right, relatedBy: .greaterThanOrEqual, toItem: caretView, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
|
||||
contentHorizontalAlignment = .left
|
||||
//set correct color after layout
|
||||
changeCaretColor()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user