我想在保存之前在UIImage
的顶部添加图像横幅。我已经创建了这种类别的方法来做到这一点。我已检查并重新检查banner.png
存在和gradient
显示正常。在UIImage上添加图像
我在做什么错?
在此先感谢!
- (UIImage *)addBanner {
UIGraphicsBeginImageContext(CGSizeMake(self.size.width, self.size.height+50));
[self drawAtPoint:CGPointMake(0, 50)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect bannerRect = CGRectMake(0, 0, self.size.width, 50);
CGColorRef start = RGB(71, 174, 255).CGColor;
CGColorRef end = RGB(0, 80, 255).CGColor;
drawLinearGradient(context, bannerRect, start, end);
UIImage *bannerImage = [UIImage imageWithContentsOfFile:@"banner.png"];
[bannerImage drawAtPoint:CGPointMake(0, 0)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
当你运行这段代码时会发生什么? –
我得到我的图像与顶部的横幅渐变,但我的bannerImage没有显示。 – enbr
事实证明,bannerImage是零,所以造成我的问题。尽管它在应用程序包中,但我绝对乐观。 – enbr