diff --git a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m index 2251731598..82b0226e6c 100644 --- a/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m +++ b/ios/sdk/WeexSDK/Sources/Display/WXComponent+Display.m @@ -145,6 +145,9 @@ - (WXDisplayBlock)_displayBlock __strong WXComponent* sself = wself; if (sself) { + CGFloat width = bounds.size.width ?: 1; + CGFloat height = bounds.size.height ?: 1; + CGSize size = CGSizeMake(width, height); UIGraphicsBeginImageContextWithOptions(bounds.size, [sself _bitmapOpaqueWithSize:bounds.size] , 0.0); UIImage *image = [sself drawRect:bounds]; if (!image) { @@ -259,7 +262,10 @@ - (void)triggerDisplay - (CGContextRef)beginDrawContext:(CGRect)bounds { - UIGraphicsBeginImageContextWithOptions(bounds.size, [self _bitmapOpaqueWithSize:bounds.size], 0.0); + CGFloat width = bounds.size.width ?: 1; + CGFloat height = bounds.size.height ?: 1; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContextWithOptions(size, [self _bitmapOpaqueWithSize:size], 0.0); CGContextRef context = UIGraphicsGetCurrentContext(); // float scaleFactor = [[UIScreen mainScreen] scale]; diff --git a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm index a2dab80e94..96ffcd62da 100644 --- a/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm +++ b/ios/sdk/WeexSDK/Sources/Model/WXComponent.mm @@ -953,7 +953,10 @@ - (void)_configWXComponentA11yWithAttributes:(NSDictionary *)attributes - (UIImage *)imageFromLayer:(CALayer *)layer { - UIGraphicsBeginImageContextWithOptions(layer.frame.size, NO, 0); + CGFloat width = layer.frame.size.width ?: 1; + CGFloat height = layer.frame.size.height ?: 1; + CGSize size = CGSizeMake(width, height); + UIGraphicsBeginImageContextWithOptions(size, NO, 0); [layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();