WIP on textLinkCaret-images: 9676e3b Merge branch 'develop' into refactor/textLinkCaret-images Refactored to fix the issue with the contentSize of the Label

This commit is contained in:
Matt Bruce 2024-03-19 15:40:06 -05:00
commit b0a6625c49

View File

@ -121,17 +121,33 @@ open class TextLinkCaret: ButtonBase {
let space: CGFloat = VDSLayout.Spacing.space1X.value // Space between the icon and the text let space: CGFloat = VDSLayout.Spacing.space1X.value // Space between the icon and the text
var titleLabelX: CGFloat = bounds.minX + contentEdgeInsets.left
// Adjust icon and text positions based on the iconPosition // Adjust icon and text positions based on the iconPosition
switch iconPosition { switch iconPosition {
case .left: case .left:
imageView.frame.origin.x = bounds.minX + contentEdgeInsets.left
imageView.frame.origin.y = titleLabel.frame.minY + (textStyle.lineHeight - imageSize.height) / 2.0 let imageSpaceWidth = imageSize.width + space
titleLabel.frame.origin.x = imageView.frame.maxX + space let titleWidth = titleLabel.frame.width
switch contentHorizontalAlignment {
case .center:
titleLabelX = (frame.width - titleWidth) / 2
case .right, .trailing:
titleLabelX = frame.width - titleWidth
default:
titleLabelX = imageSpaceWidth
}
titleLabel.frame.origin.x = titleLabelX
imageView.frame.origin.x = titleLabelX - imageSpaceWidth
imageView.frame.origin.y = titleLabel.frame.minY + 10 / 2.0
case .right: case .right:
guard let attribtedText = titleLabel.attributedText else { return } guard let attribtedText = titleLabel.attributedText else { return }
titleLabel.frame.origin.x = titleLabelX
let textContainer = NSTextContainer(size: CGSize(width: titleLabel.bounds.width, height: CGFloat.greatestFiniteMagnitude)) let textContainer = NSTextContainer(size: CGSize(width: titleLabel.bounds.width, height: CGFloat.greatestFiniteMagnitude))
textContainer.lineFragmentPadding = 0 textContainer.lineFragmentPadding = 0
@ -149,11 +165,11 @@ open class TextLinkCaret: ButtonBase {
imageView.frame.origin.x = lastGlyphRect.maxX + space imageView.frame.origin.x = lastGlyphRect.maxX + space
imageView.frame.origin.y = lastGlyphRect.midY - imageSize.height / 2 imageView.frame.origin.y = lastGlyphRect.midY - imageSize.height / 2
} }
imageView.contentMode = .scaleAspectFit imageView.contentMode = .scaleAspectFit
} }
} }