You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[IOS] lineHeight breaks textAlignment on Button label when multiline #8151
I expect the following code to render a button with text centered inside.
But on IOS, the text aligns left as soon as there is more than one line.
<ButtontextWrap="true" textAlign="center"><FormattedString><Spantext="Start of text" /><Spantext="" /><Spantext="next part of text" /></FormattedString></Button>
see screenshot below:
1st case: content wraps inside the button and is aligned left
2nd case: content does not wrap and is aligned center as expected
EDIT:
The problem also happen in a simple button. Is it apple that does not support centered multiline label on buttons?
<Buttontext="a long text that wraps on a second line" textWrap="true" textAlign="center" />
changed the title [-][IOS] FormattedString in button is not centered and/or do not respect text-align property when wrapped (multiline)[/-][+][IOS] Button label is not centered and/or do not respect text-align property when wrapped (multiline)[/+]on Nov 28, 2019
I really used a class in my case, so my bad for the wrong attribute name on this thread, but it didn't work with the css property "text-align: center" @NickIliev
I am trying your playground right now
EDIT 1:
I have reproduced most of my use case in the playground and don't have the problem here.
On the other hand, when I copy/paste your example in my app, the bug appears again.
So there must be something in my app, but I don't know what.
EDIT 2:
the bug disappears when I remove the following css property: line-height: 1.2
changed the title [-][IOS] Button label is not centered and/or do not respect text-align property when wrapped (multiline)[/-][+][IOS] lineHeight breaks textAlignment on Button label when multiline[/+]on Nov 29, 2019
@SylannBin the fix you've suggested sounds legit - you could post a PR without creating tests - the CI will run the test apps before the PR is merged so you won't have to worry about it.
Fixed in #8181 (merged January 2020): iOS text alignment is applied to the Button's titleLabel, so multiline Button text stays centered, including with line-height. Closing as completed.
Activity
[-][IOS] FormattedString in button is not centered and/or do not respect text-align property when wrapped (multiline)[/-][+][IOS] Button label is not centered and/or do not respect text-align property when wrapped (multiline)[/+]NickIliev commentedon Nov 29, 2019
@SylannBin the property is
textAlignment- on my side it is working as expected (see this Playground demo)sylann commentedon Nov 29, 2019
I really used a class in my case, so my bad for the wrong attribute name on this thread, but it didn't work with the css property "text-align: center" @NickIliev
I am trying your playground right now
EDIT 1:
I have reproduced most of my use case in the playground and don't have the problem here.
On the other hand, when I copy/paste your example in my app, the bug appears again.
So there must be something in my app, but I don't know what.
EDIT 2:
the bug disappears when I remove the following css property:
line-height: 1.2sylann commentedon Nov 29, 2019
Example playground with the bug:
https://play.nativescript.org/?template=play-tsc&id=mnTd9h&v=2
[-][IOS] Button label is not centered and/or do not respect text-align property when wrapped (multiline)[/-][+][IOS] lineHeight breaks textAlignment on Button label when multiline[/+]sylann commentedon Nov 29, 2019
The problem is caused by the following line:
NativeScript/nativescript-core/ui/text-base/text-base.ios.ts
Line 142 in 3199a39
Bug was addressed previously: (#4909)
Sadly this fix didn't took care of the
UIButtonwhich accessestextAlignmentthrough itstitleLabelobject and not directly on itself.I don't think I have enough background to handle the whole process run all the tests etc...
But the problem was solved by replacing this:
with this:
sylann commentedon Dec 3, 2019
@NickIliev Would you mind taking into account all the information I have shared since you closed this issue.
Thank you in advance.
NickIliev commentedon Dec 4, 2019
@SylannBin the fix you've suggested sounds legit - you could post a PR without creating tests - the CI will run the test apps before the PR is merged so you won't have to worry about it.
NathanWalker commentedon Oct 23, 2026
Fixed in #8181 (merged January 2020): iOS text alignment is applied to the Button's
titleLabel, so multiline Button text stays centered, including withline-height. Closing as completed.