Compare commits
1 Commits
develop
...
update/tex
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27493219a3 |
@ -51,7 +51,11 @@ open class TextLinkCaret: ButtonBase {
|
||||
$0.setSurfaceColors(VDSColor.interactiveActiveOnlight, VDSColor.interactiveActiveOndark, forState: .highlighted)
|
||||
}
|
||||
|
||||
private var imageAttribute: CaretLabelAttribute?
|
||||
private var rightCaret: CaretLabelAttribute?
|
||||
private var leftCaret: Icon = Icon().with {
|
||||
$0.name = .leftCaretBold
|
||||
$0.size = .xsmall
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Public Properties
|
||||
@ -60,8 +64,8 @@ open class TextLinkCaret: ButtonBase {
|
||||
open var iconPosition: IconPosition = .right { didSet { setNeedsUpdate() } }
|
||||
|
||||
open override var textAttributes: [any LabelAttributeModel]? {
|
||||
guard let imageAttribute else { return nil }
|
||||
return [imageAttribute]
|
||||
guard let rightCaret, iconPosition == .right else { return nil }
|
||||
return [rightCaret]
|
||||
}
|
||||
|
||||
/// UIColor used on the titleLabel text.
|
||||
@ -80,14 +84,46 @@ open class TextLinkCaret: ButtonBase {
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
accessibilityTraits = .link
|
||||
titleLabel?.lineBreakMode = .byWordWrapping
|
||||
titleLabel?.numberOfLines = 0
|
||||
|
||||
}
|
||||
|
||||
/// Used to make changes to the View based off a change events or from local properties.
|
||||
open override func updateView() {
|
||||
imageAttribute = CaretLabelAttribute(tintColor: textColor, position: iconPosition)
|
||||
if iconPosition == .right {
|
||||
leftCaret.removeFromSuperview()
|
||||
rightCaret = CaretLabelAttribute(tintColor: textColor, position: .right)
|
||||
setImage(nil, for: .normal)
|
||||
titleEdgeInsets = .zero
|
||||
contentEdgeInsets = .zero
|
||||
} else {
|
||||
if let text, text.isEmpty {
|
||||
setImage(nil, for: .normal)
|
||||
titleEdgeInsets = .zero
|
||||
contentEdgeInsets = .zero
|
||||
} else {
|
||||
leftCaret.color = textColor
|
||||
if let image = leftCaret.imageView.image, let resized = resize(image: image, size: leftCaret.size.dimensions) {
|
||||
contentVerticalAlignment = .top
|
||||
setImage(resized, for: .normal)
|
||||
imageEdgeInsets = .init(top: 5, left: 0, bottom: 0, right: VDSLayout.Spacing.space1X.value)
|
||||
titleEdgeInsets = .init(top: 0, left: VDSLayout.Spacing.space1X.value, bottom: 0, right: 0)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
super.updateView()
|
||||
}
|
||||
|
||||
func resize(image: UIImage, size: CGSize) -> UIImage? {
|
||||
UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
|
||||
image.draw(in: CGRect(origin: .zero, size: size))
|
||||
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
|
||||
UIGraphicsEndImageContext()
|
||||
return resizedImage
|
||||
}
|
||||
|
||||
/// Resets to default settings.
|
||||
open override func reset() {
|
||||
super.reset()
|
||||
@ -109,7 +145,7 @@ extension TextLinkCaret {
|
||||
var length: Int = 1
|
||||
var tintColor: UIColor
|
||||
var position: IconPosition
|
||||
var spacerWidth: CGFloat = 4.0
|
||||
var spacerWidth: CGFloat = VDSLayout.Spacing.space1X.value
|
||||
var width: CGFloat { caretSize.width + spacerWidth }
|
||||
var caretSize: CGSize { Icon.Size.xsmall.dimensions }
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user