我想出了解决方案,希望这对其他人有帮助。现在我将现有图像与阴影图像合并并使用结果图像,而不是单独添加阴影。
UIImage* image = [image imageWithFileShadow];
- (UIImage *)imageWithFileShadow {
static CGFloat pointScale = -1.0f;
if (pointScale < 0.0f) {
pointScale = [[UIScreen mainScreen] scale];
}
CGFloat imageWidth = (int)self.size.width;
CGFloat imageHeight = (int)self.size.height;
UIImage * shadowImage = [[UIImage imageNamed:@"FileShadowResizable"] resizableImageWithCapInsets:UIEdgeInsetsMake(20.0f, 24.0f, 29.0f, 24.0f)];
UIGraphicsBeginImageContextWithOptions(self.size, NO, pointScale);
[shadowImage drawInRect:CGRectMake(0.0f, 0.0f, imageWidth, imageHeight) blendMode:kCGBlendModeNormal alpha:1.0f];
[self drawInRect:CGRectMake(14.0f, 8.0f, self.size.width - 28.0f, self.size.height - 29.0f)];
UIImage * mergedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mergedImage;
}