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, Color,
input, input,
text, text,
log,
} from "doric"; } from "doric";
import { preferenceView } from "./components/PreferenceView"; import { preferenceView } from "./components/PreferenceView";
import { title } from "./utils"; import { title } from "./utils";

View File

@ -70,6 +70,28 @@ - (void)setText:(NSString *)text {
- (void)layoutSubviews { - (void)layoutSubviews {
[super layoutSubviews]; [super layoutSubviews];
if (self.contentSize.height < self.height) {
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
self.contentInset = UIEdgeInsetsMake(
0,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
self.contentInset = UIEdgeInsetsMake(
self.height - self.contentSize.height,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
} else {
self.contentInset = UIEdgeInsetsMake(
(self.height - self.contentSize.height) / 2,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
}
}
self.placeholderLabel.hidden = self.text.length > 0; self.placeholderLabel.hidden = self.text.length > 0;
if (!self.placeholderLabel.hidden) { if (!self.placeholderLabel.hidden) {
CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding; CGFloat lineFragmentPadding = self.textContainer.lineFragmentPadding;
@ -90,26 +112,8 @@ - (void)layoutSubviews {
} else { } else {
self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2 ; self.placeholderLabel.centerY = (self.height - textContainerInset.top - textContainerInset.bottom) / 2 ;
} }
} if (self.contentInset.top > 0) {
if (self.contentSize.height < self.height) { self.placeholderLabel.y = self.placeholderLabel.y - self.contentInset.top;
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
self.contentInset = UIEdgeInsetsMake(
0,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
self.contentInset = UIEdgeInsetsMake(
self.height - self.contentSize.height,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
} else {
self.contentInset = UIEdgeInsetsMake(
(self.height - self.contentSize.height) / 2,
self.contentInset.left,
self.contentInset.bottom,
self.contentInset.right);
} }
} }
} }