fixed issues for intrinsicSize

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-03-18 11:13:23 -05:00
parent 3c8176062c
commit 7d892b3190
2 changed files with 15 additions and 4 deletions

View File

@ -75,7 +75,13 @@ open class TextLink: ButtonBase {
/// The natural size for the receiving view, considering only properties of the view itself. /// The natural size for the receiving view, considering only properties of the view itself.
open override var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize guard let titleLabel else { return super.intrinsicContentSize }
// Calculate the titleLabel's intrinsic content size
let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude))
// Adjust the size if needed (add any additional padding if your design requires)
let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right,
height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom)
return adjustedSize
} }
//-------------------------------------------------- //--------------------------------------------------

View File

@ -103,9 +103,14 @@ open class TextLinkCaret: ButtonBase {
} }
/// The natural size for the receiving view, considering only properties of the view itself. /// The natural size for the receiving view, considering only properties of the view itself.
override open var intrinsicContentSize: CGSize { open override var intrinsicContentSize: CGSize {
//get the labels size, if not the button guard let titleLabel else { return super.intrinsicContentSize }
return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize // Calculate the titleLabel's intrinsic content size
let labelSize = titleLabel.sizeThatFits(CGSize(width: self.frame.width, height: CGFloat.greatestFiniteMagnitude))
// Adjust the size if needed (add any additional padding if your design requires)
let adjustedSize = CGSize(width: labelSize.width + contentEdgeInsets.left + contentEdgeInsets.right,
height: labelSize.height + contentEdgeInsets.top + contentEdgeInsets.bottom)
return adjustedSize
} }
} }