Skip to content
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

Merged
merged 1 commit into from
May 17, 2016

Conversation

Econa77
Copy link
Contributor

@Econa77 Econa77 commented May 1, 2016

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
2016-05-01 21 34 25

After
2016-05-01 21 34 45

Fix

Check

  • Check if not destroy the existing implementation and performance
    • To use the ActiveLabel in code base (AutoSizing)
    • To use the ActiveLabel in code base (AutoLayout)
    • To use the ActiveLabel in Storyboard base (AutoSizing)
    • To use the ActiveLabel in Storyboard base (AutoLayout)
    • Use custom fonts

@ndbroadbent
Copy link

ndbroadbent commented May 3, 2016

Thanks, this works great! Now I just need to figure out how to respect numberOfLines and properly truncate the text. (already fixed! f2ed0a4)

@Econa77 Econa77 changed the title [WIP] Fix auto layout size calculation Fix auto layout size calculation May 8, 2016
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))
Copy link
Contributor Author

@Econa77 Econa77 May 8, 2016

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.

@Econa77
Copy link
Contributor Author

Econa77 commented May 8, 2016

@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)
Copy link
Contributor

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...

Copy link
Contributor Author

@Econa77 Econa77 May 10, 2016

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.

2016-05-11 00 30 21

2016-05-11 00 30 35

By changing the size of textContainer, ActiveLabel can always returns the correct value.
2016-05-11 00 31 05

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

@polqf polqf merged commit 4700673 into optonaut:master May 17, 2016
@Econa77 Econa77 deleted the feature/fix-autolayout branch May 17, 2016 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants