前提:首先有一个UIView,然后重写view的 drawRect方法,在这个方法进行绘图,同时在写程序时,我们不能直接调用drawRect,需要更新绘画时,我们需要直接调用 setNeedsDisplay。
1.使用 UIBezierPath(使用这个就已经知道是在当前view的context上,所以不需要获取CGContextRef)
UIBezierPath *path = [[UIBezierPath alloc] init];
[path moveToPoint:CGPointMake(20,35)];
….
同时UIBezierPath包含多个构造方法,构造不同的图形结构,例如
UIBezierPath *path = [[UIBezierPath alloc] bezierPathWithRoundedRect:(CGRect)bounds cornerRadius:(CGFloat)radius];
2.使用Core Graphics C function
使用这个画图时,就必须首先获取context(决定要在哪里画图)。
CGContextRef context = UIGraphicsGetCurrentContext();
注意:UIView有两个比较重要的属性 opaque 和 alpha ,用来设置透明那个不透明
同时
3. UIView还可以设置动画:UIView animateWithDuration