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) UIEdgeInsets corners;
@property(nonatomic, assign) CGFloat contentWidth;
@property(nonatomic, assign) CGFloat contentHeight;
- (instancetype)init; - (instancetype)init;
- (void)measure:(CGSize)targetSize; - (void)measure:(CGSize)targetSize;

View File

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

View File

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