mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
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>
This commit is contained in:

committed by
Vasil Trifonov

parent
3c79ded42b
commit
05ef9b0ff2
@ -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 = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
|
||||
if (this.nativeTextViewProtected instanceof UIButton) {
|
||||
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
|
||||
} else {
|
||||
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>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 = (<UITextField | UITextView | UILabel>this.nativeTextViewProtected).textAlignment;
|
||||
if (this.nativeTextViewProtected instanceof UIButton) {
|
||||
paragraphStyle.alignment = (<UIButton>this.nativeTextViewProtected).titleLabel.textAlignment;
|
||||
} else {
|
||||
paragraphStyle.alignment = (<UITextField | UITextView | UILabel>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;
|
||||
|
Reference in New Issue
Block a user