标签:
#import <UIKit/UIKit.h>
@interface RQHdrawView : UIView
//在xib的关联view;
@end
--------------------------------------------------------------
#import "RQHdrawView.h"
@implementation RQHdrawView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//画布
CGContextRef ctx = UIGraphicsGetCurrentContext();
//矩形
CGRect rectFrame = CGRectMake(10, 10, 100, 100);
CGContextAddRect(ctx, rectFrame);
CGContextSetFillColorWithColor(ctx, [UIColor greenColor].CGColor);//颜色
CGContextFillPath(ctx);
//椭圆
CGRect ellipes = CGRectMake(10, 150, 100, 150);
CGContextAddEllipseInRect(ctx, ellipes);
CGContextStrokePath(ctx);
//三角形,线条
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, 200, 10);
CGContextAddLineToPoint(ctx, 150, 110);
CGContextAddLineToPoint(ctx, 250, 110);
CGContextClosePath(ctx);
CGContextSetFillColorWithColor(ctx, [UIColor yellowColor].CGColor);
CGContextFillPath(ctx);
//曲线
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, 150, 250);
CGContextAddQuadCurveToPoint(ctx, 200, 150, 250, 250);//贝塞尔曲线 控制点和结束坐标
CGContextSetLineWidth(ctx, 10);
CGContextSetStrokeColorWithColor(ctx, [UIColor orangeColor].CGColor);
CGContextStrokePath(ctx);
//圆形
CGContextAddArc(ctx, 150, 400, 40, 0, 2 * M_PI, 1);//中心点的x,曲线控制点的y,起始点,结束点,1顺时针0逆时针。
CGContextStrokePath(ctx);
}
@end
标签:
原文地址:http://www.cnblogs.com/ddzfdjijie/p/4209937.html