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