diff --git a/tns-core-modules/ui/button/button.ios.ts b/tns-core-modules/ui/button/button.ios.ts index d6cd79b31..efec3a00e 100644 --- a/tns-core-modules/ui/button/button.ios.ts +++ b/tns-core-modules/ui/button/button.ios.ts @@ -1,8 +1,8 @@ import { ControlStateChangeListener } from "ui/core/control-state-change"; import { ButtonBase, PseudoClassHandler, whiteSpaceProperty, - borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, - paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace + borderTopWidthProperty, borderRightWidthProperty, borderBottomWidthProperty, borderLeftWidthProperty, textAlignmentProperty, + paddingTopProperty, paddingRightProperty, paddingBottomProperty, paddingLeftProperty, Length, WhiteSpace, TextAlignment } from "./button-common"; export * from "./button-common"; @@ -160,6 +160,25 @@ export class Button extends ButtonBase { let left = this.effectivePaddingLeft + this.effectiveBorderLeftWidth; this.nativeView.contentEdgeInsets = { top: inset.top, left: left, bottom: inset.bottom, right: inset.right }; } + + get [textAlignmentProperty.native](): TextAlignment { + return Button.nativeToJsTextAlignment[this.nativeView.contentHorizontalAlignment]; + } + set [textAlignmentProperty.native](value: TextAlignment) { + this.nativeView.contentHorizontalAlignment = Button.jsToNativeTextAlignment[value]; + } + + private static nativeToJsTextAlignment: { [key: number]: TextAlignment } = { + [UIControlContentHorizontalAlignment.Left]: "left", + [UIControlContentHorizontalAlignment.Center]: "center", + [UIControlContentHorizontalAlignment.Right]: "right", + [UIControlContentHorizontalAlignment.Fill]: "center" + } + private static jsToNativeTextAlignment: { [key in TextAlignment]: UIControlContentHorizontalAlignment } = { + "left": UIControlContentHorizontalAlignment.Left, + "center": UIControlContentHorizontalAlignment.Center, + "right": UIControlContentHorizontalAlignment.Right + } } class TapHandlerImpl extends NSObject { diff --git a/tns-core-modules/ui/text-base/text-base.ios.ts b/tns-core-modules/ui/text-base/text-base.ios.ts index 592eeeaef..ec7c7f770 100644 --- a/tns-core-modules/ui/text-base/text-base.ios.ts +++ b/tns-core-modules/ui/text-base/text-base.ios.ts @@ -104,9 +104,7 @@ export class TextBase extends TextBaseCommon { } } set [textAlignmentProperty.native](value: TextAlignment) { - let nativeView = this.nativeView; - nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView; - // NOTE: if Button textAlignment is not enough - set also btn.contentHorizontalAlignment + let nativeView = this.nativeView; switch (value) { case "left": nativeView.textAlignment = NSTextAlignment.Left;