I'm new to iPhone programming and can't figure out how to use Core Graphics. The code I am testing with is:
- (void)drawRect:(CGRect)rect{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextClearRect(ctx, rect);
CGContextSetRGBStrokeColor(ctx, 255, 255, 0, 1);
CGContextStrokeRect(ctx, CGRectMake(195, 195, 60, 60)); }
I put it in the ViewController.m file on a default View based application but nothing happens when the application is run.
drawRect
is a method of the UIView
class, not UIViewController
. You need to create your own UIView
subclass and implement that one's drawRect
. To actually use the class, just set the class name in the xib
file that comes with the view.
There are more resource available to learn Core Graphics , you just need to google..
See some good link to know more about Core Graphics and its uses.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.