https://www.jianshu.com/p/bbb2cc485a45
第一种绘图形式:在UIView的子类方法drawRect:中绘制一个蓝色圆,使用UIKit在Cocoa为我们提供的当前上下文中完成绘图任务。
animinotestview *views = [[animinotestview alloc]initWithFrame:CGRectMake(0, 66, screenW, 200)];
[self.view addSubview:views];
views.backgroundColor = [UIColor blackColor];
- (void) drawRect: (CGRect) rect {
UIBezierPath* p = [UIBezierPathbezierPathWithOvalInRect:CGRectMake(0,0,100,100)];
// UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)];
[[UIColor blueColor] setFill];
[p fill];
}
第二种绘图形式:使用Core Graphics实现绘制蓝色圆。
- (void) drawRect: (CGRect) rect {
CGContextRef con = UIGraphicsGetCurrentContext();
CGContextAddEllipseInRect(con, CGRectMake(0,0,100,100));
CGContextSetFillColorWithColor(con, [UIColor blueColor].CGColor);
CGContextFillPath(con);
}