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

AutoLayout and custom font #45

Closed
MBLESSEN opened this issue Feb 11, 2016 · 3 comments
Closed

AutoLayout and custom font #45

MBLESSEN opened this issue Feb 11, 2016 · 3 comments

Comments

@MBLESSEN
Copy link

This was mentioned in a another issue but my problem is specific to font.

When I use a custom font, PTSans, the text is cut off at the end.

this is what it should look like:

screen shot 2016-02-11 at 12 43 02 pm

And this is what it looks with with ActiveLabel

screen shot 2016-02-11 at 12 43 58 pm

Notice the text and time stamp at the end is missing

This is a label inside a tableview cell using Automatic dimensions for the height. the cell height changes based on the size of the label.

@MBLESSEN
Copy link
Author

i removed
// public override func sizeThatFits(size: CGSize) -> CGSize {
// let currentSize = textContainer.size
// defer {
// textContainer.size = currentSize
// }
//
// textContainer.size = size
// return layoutManager.usedRectForTextContainer(textContainer).size
// }

still cuts off text can I have a more detailed explanation

@polqf
Copy link
Contributor

polqf commented Mar 11, 2016

Hi @MBLESSEN, @kaandedeoglu told you about a possible solution:

@MBLESSEN Autolayout support might also require intrinsicContentSize to be overridden. Can you please try if

let labelHeight = label.sizeThatFits(CGSize(width: CGRectGetWidth(label.frame), height: CGFloat.max)).height

label.frame.size.height = labelHeight

gives the correct height.

I've recently merged #46, and I would like to know if any of those fixes are working for you

@skrew
Copy link

skrew commented Mar 17, 2016

Works for me by adding in ActiveLabel.swift:

public override func intrinsicContentSize() -> CGSize {
        let labelHeight = self.sizeThatFits(CGSize(width: CGRectGetWidth(self.frame), height: CGFloat.max)).height
        return CGSize(width: self.frame.size.width, height: labelHeight + self.layoutMargins.top + self.layoutMargins.bottom)
    }

I don't know if this patch are correct but it's works for me.

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

No branches or pull requests

3 participants