Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Setting UILabel's paragraph style linespacing resets alignment to left #83

Open
VilemKurz opened this issue Nov 9, 2018 · 5 comments
Open
Assignees
Labels
bug Something isn't working
Milestone

Comments

@VilemKurz
Copy link

VilemKurz commented Nov 9, 2018

Set a textstyle like this to a UILabel

TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

The label has alignment set to center in storyboard.
BUG: The label has aligment left after applying the text style. In other words, setting line spacing has a side effect, it resets alignment to left.
EXPECTED BEHAVIOUR: After setting linespacing, the label should keep its alignment setting without any change.

And vice versa. If you set alignment only, line spacing is reset. So, it is not possible to do this: TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

@VilemKurz VilemKurz changed the title Setting UILabel's paragraph style linespacing overrides alignment Setting UILabel's paragraph style linespacing resets alignment to left Nov 9, 2018
@jakubpetrik
Copy link
Member

jakubpetrik commented Nov 9, 2018

You have to provide also alignment. This is intended behaviour.

TextStyle(
    .paragraphStyle([
         .lineSpacing(2.0), 
         .alignment(.natural)
     ])
)

@VilemKurz
Copy link
Author

I understand, this is how UIKit works. You set UILabel's alignment center, then attributed string with paragraph without alignment specified and boom, you have alignment left. But, shouldn't Styles shield us from these low level hassles?

@jakubpetrik
Copy link
Member

jakubpetrik commented Nov 10, 2018 via email

@VilemKurz
Copy link
Author

VilemKurz commented Nov 27, 2018

Ok, forget about mixing storyboard settings with Styles (although I think we agreed that Styles should preserve storyboard settings - in other words Styles should not change other values than set through Styles). You even can not do this, in a pure Styles fashion TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

btw read twice what did you write:
"You set the style and expect it no side effects. In other words it should clear out everything and apply only the properties which are defined in the style"

"expect it no side effects" is mutually exclusive with "it should clear out everything"

@jakubpetrik
Copy link
Member

:D you are correct. I misworded that one. What I meant was in that second sentence: In other words it should clear out everything and apply only the properties which are defined in the style.

Anyway. I personally don't like that idea of preserving settings from storyboard since it can cause lot of confusion, but I will look into it.

You even can not do this, in a pure Styles fashion TextStyle(.paragraphStyle([.alignment(.center)])) + TextStyle(.paragraphStyle([.lineSpacing(2.0)]))

this is a bug that needs to be fixed. 👍

@jakubpetrik jakubpetrik self-assigned this Dec 19, 2018
@jakubpetrik jakubpetrik added the bug Something isn't working label Dec 19, 2018
@jakubpetrik jakubpetrik added this to the 1.0.0 milestone Dec 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants