iOS: add stretch inset dictionary

This commit is contained in:
王劲鹏 2020-04-17 14:40:33 +08:00 committed by osborn
parent 014ac5b0f1
commit 36eaf35cd0
2 changed files with 15 additions and 10 deletions

View File

@ -119,9 +119,9 @@ class ImageDemo extends Panel {
scaleType: ScaleType.ScaleToFill, scaleType: ScaleType.ScaleToFill,
layoutConfig: layoutConfig().just(), layoutConfig: layoutConfig().just(),
stretchInset: { stretchInset: {
left: 374, left: 125,
top: 0, top: 0,
right: 66, right: 22,
bottom: 0 bottom: 0
} }
}) })

View File

@ -40,6 +40,7 @@ @interface DoricImageNode ()
@property(nonatomic, strong) NSNumber *errorColor; @property(nonatomic, strong) NSNumber *errorColor;
@property(nonatomic, strong) NSString *errorImage; @property(nonatomic, strong) NSString *errorImage;
@property(nonatomic, strong) UIVisualEffectView *blurEffectView; @property(nonatomic, strong) UIVisualEffectView *blurEffectView;
@property(nonatomic, strong) NSDictionary *stretchInsetDic;
@end @end
@implementation DoricImageNode @implementation DoricImageNode
@ -227,16 +228,20 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
} }
} else if ([@"stretchInset" isEqualToString:name]) { } else if ([@"stretchInset" isEqualToString:name]) {
NSDictionary * stretchInsetDic = (NSDictionary *)prop; self.stretchInsetDic = (NSDictionary *)prop;
CGFloat left = [stretchInsetDic[@"left"] floatValue];
CGFloat top = [stretchInsetDic[@"top"] floatValue];
CGFloat right = [stretchInsetDic[@"right"] floatValue];
CGFloat bottom = [stretchInsetDic[@"bottom"] floatValue];
UIImage *scaled = [[UIImage alloc] initWithCGImage:view.image.CGImage scale:[[UIScreen mainScreen] scale] orientation:view.image.imageOrientation];
UIImage *result = [scaled resizableImageWithCapInsets:UIEdgeInsetsMake(0, 125, 0, 22) resizingMode:UIImageResizingModeStretch];
view.image = result;
} else { } else {
[super blendView:view forPropName:name propValue:prop]; [super blendView:view forPropName:name propValue:prop];
} }
} }
- (void)afterBlended:(NSDictionary *)props {
if (self.stretchInsetDic != nil) {
CGFloat left = [self.stretchInsetDic[@"left"] floatValue];
CGFloat top = [self.stretchInsetDic[@"top"] floatValue];
CGFloat right = [self.stretchInsetDic[@"right"] floatValue];
CGFloat bottom = [self.stretchInsetDic[@"bottom"] floatValue];
UIImage *result = [self.view.image resizableImageWithCapInsets:UIEdgeInsetsMake(top, left, bottom, right) resizingMode:UIImageResizingModeStretch];
self.view.image = result;
}
}
@end @end