iOS:TextNode use content size

This commit is contained in:
pengfei.zhou 2021-09-09 11:58:37 +08:00 committed by osborn
parent 88c594ae10
commit 228c2c131c
3 changed files with 11 additions and 10 deletions

View File

@ -105,6 +105,9 @@ typedef NS_ENUM(NSInteger, DoricGravity) {
@property(nonatomic, assign) UIEdgeInsets corners;
@property(nonatomic, assign) CGFloat contentWidth;
@property(nonatomic, assign) CGFloat contentHeight;
- (instancetype)init;
- (void)measure:(CGSize)targetSize;

View File

@ -83,8 +83,6 @@ - (DoricLayout *)doricLayout {
@end
@interface DoricLayout ()
@property(nonatomic, assign) CGFloat contentWidth;
@property(nonatomic, assign) CGFloat contentHeight;
@end
@implementation DoricLayout

View File

@ -39,19 +39,19 @@ - (void)drawTextInRect:(CGRect)rect {
self.doricLayout.paddingBottom,
self.doricLayout.paddingRight));
if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
CGRect realRect = [self textRectForBounds:rect
limitedToNumberOfLines:self.numberOfLines];
rect.origin.y = self.doricLayout.paddingTop;
rect.size.height = realRect.size.height;
rect.size.height = self.doricLayout.contentHeight;
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
CGRect realRect = [self textRectForBounds:rect
limitedToNumberOfLines:self.numberOfLines];
rect.origin.y = self.height - realRect.size.height - self.doricLayout.paddingBottom;
rect.size.height = realRect.size.height;
rect.origin.y = self.height - self.doricLayout.contentHeight - self.doricLayout.paddingBottom;
rect.size.height = self.doricLayout.contentHeight;
}
rect.size.width = MAX(0.01f, rect.size.width);
[super drawTextInRect:rect];
}
- (CGSize)sizeThatFits:(CGSize)size {
return [super sizeThatFits:size];
}
@end
@interface DoricTextNode ()