Compare commits
No commits in common. "b0a6625c49a2d74a020fee57b681c8590566aebd" and "9676e3b4d067de1ed94546cab6cba632e12310e9" have entirely different histories.
b0a6625c49
...
9676e3b4d0
@ -121,55 +121,39 @@ 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
|
||||||
let imageSpaceWidth = imageSize.width + space
|
imageView.frame.origin.y = titleLabel.frame.minY + (textStyle.lineHeight - imageSize.height) / 2.0
|
||||||
let titleWidth = titleLabel.frame.width
|
titleLabel.frame.origin.x = imageView.frame.maxX + space
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
let layoutManager = NSLayoutManager()
|
let layoutManager = NSLayoutManager()
|
||||||
layoutManager.addTextContainer(textContainer)
|
layoutManager.addTextContainer(textContainer)
|
||||||
|
|
||||||
let textStorage = NSTextStorage(attributedString: attribtedText)
|
let textStorage = NSTextStorage(attributedString: attribtedText)
|
||||||
textStorage.addLayoutManager(layoutManager)
|
textStorage.addLayoutManager(layoutManager)
|
||||||
|
|
||||||
let lastGlyphIndex = layoutManager.glyphIndexForCharacter(at: attribtedText.string.utf16.count - 1)
|
let lastGlyphIndex = layoutManager.glyphIndexForCharacter(at: attribtedText.string.utf16.count - 1)
|
||||||
var lastGlyphRect = layoutManager.boundingRect(forGlyphRange: NSRange(location: lastGlyphIndex, length: 1), in: textContainer)
|
var lastGlyphRect = layoutManager.boundingRect(forGlyphRange: NSRange(location: lastGlyphIndex, length: 1), in: textContainer)
|
||||||
|
|
||||||
lastGlyphRect.origin.x += titleLabel.frame.origin.x
|
lastGlyphRect.origin.x += titleLabel.frame.origin.x
|
||||||
lastGlyphRect.origin.y += titleLabel.frame.origin.y
|
lastGlyphRect.origin.y += titleLabel.frame.origin.y
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user