I have this code, and it is working exactly as desired:
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
However, for this line:
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
I am getting the warning (not error):
No '-renderInContext' method found.
How can I have t开发者_运维知识库his warning, if in fact the method is working? If I were to simply comment out this line, my code fails; so clearly the line, and thus the method, are in fact working.
You need to add reference to the header file for CALayer
- #import <QuartzCore/QuartzCore.h>
. You might also need to add the QuartzCore.framework
to your project.
It's saying this because the compiler can't find the definition of that method. You need to add this line:
#import <QuartzCore/QuartzCore.h>
to the start of the .m
file. You may also need to add the QuartzCore framework to your project.
(the reason your app works is that the method is available at run time)
You are probably having the same issue as this guy. Make sure you add QuartzCore.
精彩评论