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

sizeToFit not implemented #92

Open
Pe-te opened this issue Jun 6, 2018 · 7 comments
Open

sizeToFit not implemented #92

Pe-te opened this issue Jun 6, 2018 · 7 comments

Comments

@Pe-te
Copy link
Contributor

Pe-te commented Jun 6, 2018

Hi, I'm trying to calculate the height the WSTagsField needs in my view, any way to get that easily? I tried using sizeThatFits, but it seems not implemented and is returning 0:

    let fullSize = CGSize(width: width, height: CGFloat.greatestFiniteMagnitude)
    var totalHeight: CGFloat = 0.0
    totalHeight += titleLabel.sizeThatFits(fullSize).height // this works fine for a normal label
    totalHeight += tagsField.sizeThatFits(fullSize).height // returns 0
    return totalHeight
@ricardopereira
Copy link
Member

@Pe-te Yes, you're right. sizeThatFits implementation is missing 😕 Let me see if I can fix that today.
Thanks for opening an issue.

@Pe-te
Copy link
Contributor Author

Pe-te commented Jun 7, 2018

Take your time, guess that's a tricky one!

For now I am using a workaround with onDidChangeHeightTo where I store the value in a global variable, but that feels really messy, so a clean solution would be very welcome.

@ricardopereira
Copy link
Member

@Pe-te Implemented eb54068.
Could you please test using the master branch. Thanks!

@Pe-te
Copy link
Contributor Author

Pe-te commented Jun 9, 2018

Cool, will check first thing monday morning!

I'm not using insets, but don't you need to subtract left and right from the width? I could be wrong though, haven't looked at the code in detail yet.

@ricardopereira
Copy link
Member

@Pe-te That's a good point. Does the UILabel have in consideration the insets for the width size?

@Pe-te
Copy link
Contributor Author

Pe-te commented Jun 11, 2018

You mean the UILabel titleLabel in my example above? I'm not setting any insets there, so it has the default insets. But it looks like you cannot just modify label insets by default anyway.

For WSTagsField I use the following insets. Works as expected, thanks!

    // outer padding for whole tagsField
    tagsField.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
    // inner padding for every tag
    tagsField.layoutMargins = UIEdgeInsets(top: 6, left: 12, bottom: 6, right: 12)

I also tried adding contentInsets for top and buttom, those work fine, even when you add like 40 tags.

But there are problems when you try to set left and right insets. For those the sizeToFit().height is way too large. This happens already with small amounts like 2-3 tags, but gets a lot worse for bigger amounts. Maybe an inverted sign?

I gave the view a backgroundcolor and it looks fine as expected, all paddings are applied correctly. Just sizeToFit() is acting weird.

Best guess: First all paddings need to be removed, then size calculation on the smaller canvas, then adding all four paddings again.

@ricardopereira
Copy link
Member

@Pe-te Thanks for the feedback. I'll look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants