我想在保存之前在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