From 05ef9b0ff24bb2dec2542af5891022c5f3352064 Mon Sep 17 00:00:00 2001 From: Romain Vincent Date: Tue, 21 Jan 2020 17:39:42 +0100 Subject: [PATCH] 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 Co-authored-by: Vasil Trifonov --- nativescript-core/ui/text-base/text-base.ios.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/nativescript-core/ui/text-base/text-base.ios.ts b/nativescript-core/ui/text-base/text-base.ios.ts index e47cf139b..568f2ef03 100644 --- a/nativescript-core/ui/text-base/text-base.ios.ts +++ b/nativescript-core/ui/text-base/text-base.ios.ts @@ -139,7 +139,12 @@ export class TextBase extends TextBaseCommon { const paragraphStyle = NSMutableParagraphStyle.alloc().init(); paragraphStyle.lineSpacing = this.lineHeight; // make sure a possible previously set text alignment setting is not lost when line height is specified - paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + if (this.nativeTextViewProtected instanceof UIButton) { + paragraphStyle.alignment = (this.nativeTextViewProtected).titleLabel.textAlignment; + } else { + paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + } + if (this.nativeTextViewProtected instanceof UILabel) { // make sure a possible previously set line break mode is not lost when line height is specified paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode; @@ -192,7 +197,12 @@ export class TextBase extends TextBaseCommon { const paragraphStyle = NSMutableParagraphStyle.alloc().init(); paragraphStyle.lineSpacing = style.lineHeight; // make sure a possible previously set text alignment setting is not lost when line height is specified - paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + if (this.nativeTextViewProtected instanceof UIButton) { + paragraphStyle.alignment = (this.nativeTextViewProtected).titleLabel.textAlignment; + } else { + paragraphStyle.alignment = (this.nativeTextViewProtected).textAlignment; + } + if (this.nativeTextViewProtected instanceof UILabel) { // make sure a possible previously set line break mode is not lost when line height is specified paragraphStyle.lineBreakMode = this.nativeTextViewProtected.lineBreakMode;