Skip to content

Commit 05ef9b0

Browse files
sylannromain20100-rwigodtopuzovvtrifonov
committed
fix(8151): button textAlignment on IOS (UIButton) (#8181)
When setting the format of a "text view", we need to recover existing values for properties that will get default values otherwise. The "textAlignment" of a UIButton is available through a "titleLabel" object instead of directly on itself (see IOS documentation fo UIButton). Co-authored-by: Romain Vincent <54814371+romain20100@users.noreply.github.com> Co-authored-by: Dimitar Topuzov <dtopuzov@gmail.com> Co-authored-by: Vasil Trifonov <v.trifonov@gmail.com>
1 parent 3c79ded commit 05ef9b0

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

nativescript-core/ui/text-base/text-base.ios.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ export class TextBase extends TextBaseCommon {
139139
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
140140
paragraphStyle.lineSpacing = this.lineHeight;
141141
// make sure a possible previously set text alignment setting is not lost when line height is specified
142-
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
142+
if (this.nativeTextViewProtected instanceof UIButton) {
143+
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
144+
} else {
145+
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
146+
}
147+
143148
if (this.nativeTextViewProtected instanceof UILabel) {
144149
// make sure a possible previously set line break mode is not lost when line height is specified
145150
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;
@@ -192,7 +197,12 @@ export class TextBase extends TextBaseCommon {
192197
const paragraphStyle = NSMutableParagraphStyle.alloc().init();
193198
paragraphStyle.lineSpacing = style.lineHeight;
194199
// make sure a possible previously set text alignment setting is not lost when line height is specified
195-
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
200+
if (this.nativeTextViewProtected instanceof UIButton) {
201+
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
202+
} else {
203+
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
204+
}
205+
196206
if (this.nativeTextViewProtected instanceof UILabel) {
197207
// make sure a possible previously set line break mode is not lost when line height is specified
198208
paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;

0 commit comments

Comments
 (0)