心形图形的源代码(iOS)

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值