From f9e7da14b8944653be3ca87b226e617823566d7d Mon Sep 17 00:00:00 2001 From: Romain Vincent Date: Mon, 9 Dec 2019 00:21:02 +0100 Subject: [PATCH] fix(8151): button textAlignment on IOS (UIButton) 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). --- 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 e47cf139bc..568f2ef038 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;