luispadron / UIEmptyState

An empty state control to give visually appealing context when building iOS applications.
MIT License
178 stars 34 forks source link

Button does not resize to fit text #16

Open im-jersh opened 6 years ago

im-jersh commented 6 years ago

It seems like setting the font size to some arbitrary value depending on the device type will cause the action button's title to be truncated.

Here's an 8 Plus with the font size set to 17pt: simulator screen shot - iphone 8 plus - 2018-02-22 at 14 22 37

And the same device with the font size set to 16pt: simulator screen shot - iphone 8 plus - 2018-02-22 at 14 23 07

luispadron commented 6 years ago

You need to adjust the buttons size to fit the font, you can do this with the data source methods.

im-jersh commented 6 years ago

But even the documentation says the default implementation should size the button to fit the title PLUS some padding yet this is not the result I'm seeing. Don't mind sizing the button myself, just think the docs should be consistent with that requirement if it is in fact a requirement.

screen shot 2018-02-22 at 3 28 12 pm

im-jersh commented 6 years ago

Also, if simulate padding by adding blank spaces to the beginning and end of my button title, then the issue is resolved. Definitely think this is issue is a bug that needs to be addressed internally. Can try to track it down later and submit a PR.

luispadron commented 6 years ago

You're right, my bad. This does seem like a bug that should be looked into.

The code which handles this constraint for the button:

let size = buttonSize ?? self.buttonTitle?.size() ??
                    self.buttonImage?.size ??
                    CGSize(width: 0, height: 0)

button.heightAnchor.constraint(equalToConstant: size.height).isActive = true
button.widthAnchor.constraint(equalToConstant: size.width).isActive = true

I don't have time currently to look at this, but if you want to take a look and submit a PR that would be great!