Core Graphics

-(void)drawRect:(CGRect)rect

{

//    CGContextRef context = UIGraphicsGetCurrentContext();

//    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

//画弧线

//    CGContextMoveToPoint(context, 50, 0);

//    CGContextAddArc(context, 50, 50, 50, 270*M_PI/180, 0, 0);

//    CGContextStrokePath(context);

//画椭圆形

//    CGContextAddEllipseInRect(context, CGRectMake(0, 0, 300, 300));

//    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);

//    CGContextFillPath(context);

//画曲线

CGContextRefcontext =UIGraphicsGetCurrentContext();

CGContextSetLineWidth(context,1);

CGContextSetStrokeColorWithColor(context, [UIColorredColor].CGColor);

CGContextMoveToPoint(context,100,100);

//(150, 100):控制点,(200, 200):终点

CGContextAddQuadCurveToPoint(context,150,100,200,200);

CGContextStrokePath(context);

//贝塞尔路径画圆

UIBezierPath*bezierPath = [UIBezierPathbezierPathWithArcCenter:CGPointMake(120,120)

radius:100

startAngle:(CGFloat) -M_PI_2

endAngle:(CGFloat)2*M_PI*_progress

clockwise:YES];

bezierPath.lineWidth=10;

[[UIColorblueColor]setStroke];

[bezierPathstroke];

//CAShapeLayer

}

//动态更新贝塞尔路径

-(void)startAnimation

{

NSTimer*timer = [NSTimerscheduledTimerWithTimeInterval:1

target:self

selector:@selector(update)

userInfo:nil

repeats:YES];

[timerfire];

}

-(void)update

{

_progress+=0.1;

[selfsetNeedsDisplay];

}

//蒙版

- (void)viewDidLoad {

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

UIImageView*backgroundImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(40,80,198,162)];

UIImageView*maskImageView = [[UIImageViewalloc]initWithFrame:backgroundImageView.bounds];

[maskImageViewsetImage:[UIImageimageNamed:@"bg.png"]];

backgroundImageView.layer.mask= maskImageView.layer;

UIImageView*imageView = [[UIImageViewalloc]initWithFrame:backgroundImageView.bounds];

[imageViewsetImage:[UIImageimageNamed:@"RI8[50WUPQ@TR~917UULUCR.jpg"]];

[backgroundImageViewaddSubview:imageView];

[self.viewaddSubview:backgroundImageView];

}




例子:

- (instancetype)initWithFrame:(CGRect)frame

{

self = [super initWithFrame:frame];

if (self) {

[self setBackgroundColor:[UIColor clearColor]];

}

return self;

}

- (void)drawRect:(CGRect)rect {

// Drawing code

CGContextRef ctx =  UIGraphicsGetCurrentContext();

//圆形

CGContextSetStrokeColorWithColor(ctx, [UIColor whiteColor].CGColor);

CGContextAddEllipseInRect(ctx,CGRectMake(0, 0, 100,100));

CGContextSetFillColorWithColor(ctx, [UIColor redColor].CGColor);

CGContextFillPath(ctx );

self.backgroundColor = [UIColor redColor];

//直线

//    [[UIColor redColor] set ];

//    CGContextSetLineWidth(ctx, 3);

//    CGContextMoveToPoint(ctx, 0, 100);

//    CGContextAddLineToPoint(ctx, 500, 100);

//    CGContextStrokePath(ctx);

//绘制图片

UIImage *img = [UIImage imageNamed:@"test"];

[img drawAtPoint:CGPointMake(0, 200)];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容