iOS编程,画一个心形图形。
Objective-C实现,可以自己调整一下位置的:
-(void)drawRect:(CGRect)rect{
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx , 100, 125);
CGContextAddCurveToPoint(ctx, 100,125,110,100,125,125);
CGContextAddCurveToPoint(ctx, 125, 125, 140, 100, 150, 125);
CGContextAddCurveToPoint(ctx, 150, 125, 150, 150,125,150);
CGContextAddCurveToPoint(ctx, 125,150, 100,150,100,125);
CGPoint points[9];
points[0]=CGPointMake(100,125);
points[1]=CGPointMake(110,100);
points[2]=CGPointMake(125,125);
points[3]=CGPointMake(140,100);
points[4]=CGPointMake(150,125);
points[5]=CGPointMake(150,150);
points[6]=CGPointMake(125,150);
points[7]=CGPointMake(100,150);
points[8]=CGPointMake(100,125);
CGContextClosePath(ctx);
CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
CGContextFillPath(ctx);
}
将心形图形应用到图标小程序中。
参考资料:
1.Core Graphics 一: CGContext基本绘制 - 简书
https://www.jianshu.com/p/ef40476ab035
2.《使用二阶贝塞尔曲线画爱心》
https://juejin.cn/post/7084969126724108301
以上内容仅供参考,如有不对,欢迎指正。
首次编辑:2025/03/16 06:50
再次编辑:2025/03/16 13:58