enbr
enbr

Reputation: 1203

Add image on top of UIImage

I am trying to add a image banner on top of a UIImage before saving it. I have created this category method to do so. I have checked and rechecked that banner.png exists and the gradient shows up fine.

What am I doing wrong?

Thanks in advance!

- (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;
}

Upvotes: 0

Views: 2421

Answers (2)

enbr
enbr

Reputation: 1203

Apparently [UIImage imageWithContentsOfFile:] requires a full path. Changing it to [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"banner.png"]] worked.

Upvotes: 1

Related Questions