fix: textView's placeholder position error bug .

This commit is contained in:
吴尚昆 2022-07-08 14:34:37 +08:00 committed by osborn
parent d412d456bb
commit 6eb014eab3
2 changed files with 26 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import {
Color,
input,
text,
log,
} from "doric";
import { preferenceView } from "./components/PreferenceView";
import { title } from "./utils";

View File

@ -70,27 +70,6 @@ - (void)setText:(NSString *)text {
- (void)layoutSubviews {
[super layoutSubviews];
self.placeholderLabel.hidden = self.text.length > 0;
if (!self.placeholderLabel.hidden) {
CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding;
UIEdgeInsets textContainerInset = self.textContainerInset;
self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left;
CGFloat 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;
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
self.placeholderLabel.y = textContainerInset.top;
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
self.placeholderLabel.y = self.height - textContainerInset.bottom - fitSize.height;
} else {
self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2;
}
}
if (self.contentSize.height < self.height) {
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
self.contentInset = UIEdgeInsetsMake(
@ -112,6 +91,31 @@ - (void)layoutSubviews {
self.contentInset.right);
}
}
self.placeholderLabel.hidden = self.text.length > 0;
if (!self.placeholderLabel.hidden) {
CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding;
UIEdgeInsets textContainerInset = self.textContainerInset;
self.placeholderLabel.x = lineFragmentPadding + textContainerInset.left;
CGFloat 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;
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
self.placeholderLabel.y = textContainerInset.top;
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
self.placeholderLabel.y = self.height - textContainerInset.bottom - fitSize.height ;
} else {
self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2 ;
}
if (self.contentInset.top > 0) {
self.placeholderLabel.y = self.placeholderLabel.y - self.contentInset.top;
}
}
}
- (CGSize)sizeThatFits:(CGSize)size {