iOS: fix text alignment sync on placeholder label

This commit is contained in:
王劲鹏 2021-06-29 16:05:59 +08:00 committed by osborn
parent ecb2839a10
commit 8366e1c508

View File

@ -56,8 +56,14 @@ - (void)layoutSubviews {
UIEdgeInsets textContainerInset = self.textContainerInset; UIEdgeInsets textContainerInset = self.textContainerInset;
self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left; self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left;
self.placeholderLabel.y = textContainerInset.top; 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 { - (CGSize)sizeThatFits:(CGSize)size {
@ -108,6 +114,7 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
alignment = NSTextAlignmentRight; alignment = NSTextAlignmentRight;
} }
view.textAlignment = alignment; view.textAlignment = alignment;
view.placeholderLabel.textAlignment = alignment;
} else if ([name isEqualToString:@"multiline"]) { } else if ([name isEqualToString:@"multiline"]) {
BOOL value = [(NSNumber *) prop boolValue]; BOOL value = [(NSNumber *) prop boolValue];
if (!value) { if (!value) {