iOS: DoricLayout fix missing property

This commit is contained in:
pengfei.zhou 2022-08-24 16:18:25 +08:00 committed by osborn
parent c8365973f0
commit 7749ea2ea2

View File

@ -28,6 +28,7 @@
@interface DoricTextView : UILabel @interface DoricTextView : UILabel
@property(nonatomic, assign) DoricGravity gravity; @property(nonatomic, assign) DoricGravity gravity;
@property(nonatomic, assign) CGFloat contentHeight;
@end @end
@implementation DoricTextView @implementation DoricTextView
@ -41,17 +42,19 @@ - (void)drawTextInRect:(CGRect)rect {
self.doricLayout.paddingRight)); self.doricLayout.paddingRight));
if ((self.gravity & DoricGravityTop) == DoricGravityTop) { if ((self.gravity & DoricGravityTop) == DoricGravityTop) {
rect.origin.y = self.doricLayout.paddingTop; rect.origin.y = self.doricLayout.paddingTop;
rect.size.height = self.doricLayout.contentHeight; rect.size.height = self.contentHeight;
} else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) { } else if ((self.gravity & DoricGravityBottom) == DoricGravityBottom) {
rect.origin.y = self.height - self.doricLayout.contentHeight - self.doricLayout.paddingBottom; rect.origin.y = self.height - self.contentHeight - self.doricLayout.paddingBottom;
rect.size.height = self.doricLayout.contentHeight; rect.size.height = self.contentHeight;
} }
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 { - (CGSize)sizeThatFits:(CGSize)size {
return [super sizeThatFits:size]; CGSize result = [super sizeThatFits:size];
self.contentHeight = result.height;
return result;
} }
@end @end