fix: textView's placeholder position error bug .
This commit is contained in:
parent
d412d456bb
commit
6eb014eab3
@ -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";
|
||||||
|
@ -70,27 +70,6 @@ - (void)setText:(NSString *)text {
|
|||||||
|
|
||||||
- (void)layoutSubviews {
|
- (void)layoutSubviews {
|
||||||
[super 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.contentSize.height < self.height) {
|
||||||
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
|
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
|
||||||
self.contentInset = UIEdgeInsetsMake(
|
self.contentInset = UIEdgeInsetsMake(
|
||||||
@ -112,6 +91,31 @@ - (void)layoutSubviews {
|
|||||||
self.contentInset.right);
|
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 {
|
- (CGSize)sizeThatFits:(CGSize)size {
|
||||||
|
Reference in New Issue
Block a user