From 5b3d45f607488b2fa46cdf8d9c5c4289a4dc1f86 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Wed, 8 Sep 2021 20:19:41 +0800 Subject: [PATCH] iOS: Text textAligment support Top and Bottom --- doric-iOS/Pod/Classes/Shader/DoricTextNode.m | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m index 7f6f1b48..9b0a0667 100644 --- a/doric-iOS/Pod/Classes/Shader/DoricTextNode.m +++ b/doric-iOS/Pod/Classes/Shader/DoricTextNode.m @@ -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"]) { @@ -289,10 +304,10 @@ - (UIImage *)gradientImageFromColors:(NSArray *)colors if (@available(iOS 10.0, *)) { UIGraphicsImageRendererFormat *format = [[UIGraphicsImageRendererFormat alloc] init]; format.scale = [UIScreen mainScreen].scale; - UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc]initWithSize:imgSize format:format]; - UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { + UIGraphicsImageRenderer *render = [[UIGraphicsImageRenderer alloc] initWithSize:imgSize format:format]; + UIImage *image = [render imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) { CGContextRef context = rendererContext.CGContext; - + CGContextSaveGState(context); CGColorSpaceRef colorSpace = CGColorGetColorSpace((__bridge CGColorRef) colors.lastObject); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, locations);