iOS: Text textAligment support Top and Bottom

This commit is contained in:
pengfei.zhou 2021-09-08 20:19:41 +08:00 committed by osborn
parent 41e610e424
commit 5b3d45f607

View File

@ -26,17 +26,31 @@
#import "Doric.h"
@interface DoricTextView : UILabel
@property(nonatomic, assign) DoricGravity gravity;
@end
@implementation DoricTextView
- (void)drawTextInRect:(CGRect)rect {
[super drawTextInRect:UIEdgeInsetsInsetRect(
rect = UIEdgeInsetsInsetRect(
rect,
UIEdgeInsetsMake(
self.doricLayout.paddingTop,
self.doricLayout.paddingLeft,
self.doricLayout.paddingBottom,
self.doricLayout.paddingRight))];
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;
} 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.size.width = MAX(0.01f,rect.size.width);
[super drawTextInRect:rect];
}
@end
@ -93,6 +107,7 @@ - (void)blendView:(UILabel *)view forPropName:(NSString *)name propValue:(id)pro
} else {
view.textAlignment = alignment;
}
((DoricTextView *) view).gravity = gravity;
} else if ([name isEqualToString:@"maxLines"]) {
view.numberOfLines = [prop integerValue];
} else if ([name isEqualToString:@"fontStyle"]) {