SwiftKickMobile / SwiftMessages

A very flexible message bar for UIKit and SwiftUI.
MIT License
7.3k stars 742 forks source link

CardView doesn't center pure textural content #355

Closed danielsaidi closed 4 years ago

danielsaidi commented 4 years ago

We use CardView.xib to display a pure text message, without an icon, title or button. We set the body label's text alignment to center, since we want the text centered in the card.

The problem is that the content is only centered when the text is long enough to wrap over two lines. We can fix this by opening CardView.xib and set Alignment to Fill for the vertical, innermost stack view.

We considered a couple of ways this could be done, but ended up in that it would be nice to have a "pure text card" view, for which the content is centered. We will add such a xib to our project now, but it would be nice if the library could include such a xib as well.

wtmoose commented 4 years ago

The nibs are intended to supply basic form factors only. Supporting all of the permutations of form factor and content wouldn't be practical IMO. The nibs are provided so you can copy them into your project and easily modify them to suit your specific needs.

In any case, I'm fine with changing the alignment to Fill. Did you foresee an issue with that?

danielsaidi commented 4 years ago

Hi @wtmoose !

Yeah, you are right - the docs emphazise that you should copy the xibs and use them as templates. However, I found it strange (and a little wrong hehe) that the text is left-aligned if it's short, but centered if it's longer and spans over several lines.

If fill solves the problem, that'd be great. I haven't tried the combo icon + text + fill + button, so I'm not sure if it causes any other side-effects.

wtmoose commented 4 years ago

I put a fix for this on the head of master if you want to try it. Will release soon.

danielsaidi commented 4 years ago

Sorry for the slow reply, we’ve been busy at work. Great, I’ll try it and see if it works :)

dasoga commented 4 years ago

Hi @wtmoose i tried to center the body text (not using any other element) and it worked if I copy the framework manually, any plans to release this in cocoapods?

thanks!

bukerapp commented 4 years ago

Same question as above, thank you.

kientux commented 4 years ago

Same issue, still waiting for new release which fixes this. Until then, if you don't want to copy and edit the xib, just use this (a little ugly) fix:

if let stackView = view.titleLabel?.superview as? UIStackView {
    stackView.alignment = .fill
}
wtmoose commented 4 years ago

Included in 8.0.0 release