From 8366e1c50869e02efece590a055a902704c8ae7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 29 Jun 2021 16:05:59 +0800 Subject: [PATCH] iOS: fix text alignment sync on placeholder label --- doric-iOS/Pod/Classes/Shader/DoricInputNode.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m index 0964840e..f3d03c2a 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricInputNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricInputNode.m @@ -56,8 +56,14 @@ - (void)layoutSubviews { UIEdgeInsets textContainerInset = self.textContainerInset; self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left; self.placeholderLabel.y = textContainerInset.top; - self.placeholderLabel.width = self.width - lineFragmentPadding * 2 - textContainerInset.left - textContainerInset.right; - [self.placeholderLabel sizeToFit]; + + float desiredWidth = self.width - lineFragmentPadding * 2 - textContainerInset.left - textContainerInset.right; + CGSize fitSize = [self.placeholderLabel sizeThatFits:CGSizeMake(desiredWidth, 0)]; + + if (fitSize.width < desiredWidth) { + self.placeholderLabel.width = desiredWidth; + } + self.placeholderLabel.height = fitSize.height; } - (CGSize)sizeThatFits:(CGSize)size { @@ -108,6 +114,7 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue: alignment = NSTextAlignmentRight; } view.textAlignment = alignment; + view.placeholderLabel.textAlignment = alignment; } else if ([name isEqualToString:@"multiline"]) { BOOL value = [(NSNumber *) prop boolValue]; if (!value) {