-
Notifications
You must be signed in to change notification settings - Fork 687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix auto layout size calculation #77
Conversation
Thanks, this works great! |
dcc4f91
to
5bd9bd1
Compare
5bd9bd1
to
c9f9bad
Compare
let superSize = super.intrinsicContentSize() | ||
textContainer.size = CGSize(width: superSize.width, height: CGFloat.max) | ||
let size = layoutManager.usedRectForTextContainer(textContainer) | ||
return CGSize(width: size.width, height: ceil(size.height)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When numberOfLine
and lineSpacing
is 0 in this calculation, the normal UILabel has confirmed the same size.
@poolqf Please review code 🙏 |
// MARK: - Auto layout | ||
public override func intrinsicContentSize() -> CGSize { | ||
let superSize = super.intrinsicContentSize() | ||
textContainer.size = CGSize(width: superSize.width, height: CGFloat.max) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @Econa77, I am not sure about changing the textContainer size and not revert it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I changed the size of textContainer
is as follows.
If don't change the size, It don't fit the calculation of height
Calculation of height will be calculated as the upper limit of the height that has been set on the Storyboard.
By changing the size of textContainer
, ActiveLabel can always returns the correct value.
The reason I have not reverted size is always changed current label size in drawTextInRect
.
https://github.com/optonaut/ActiveLabel.swift/blob/master/ActiveLabel/ActiveLabel.swift#L116
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Econa77, thanks for the explanation. Just one last thing before merging.
Is drawTextInRect always executed after instrinsicContentSize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@poolqf
Yes, it has been executed after instrinsicContentSize
.
Size calculation of AutoLayout has shifted to when using the ActiveLabel of customized state in the Storyboard.
So it has been changed to return the correct size using the
layoutManager
Before
After
Fix
Check