ios开发——Quartz路径

四个图元:

1.点

2.线段

3.弧

4.贝塞尔曲线

实例:使用贝塞尔曲线

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //创建根视图控制器
    ViewController* rootViewController = [[ViewController alloc] init];
    //创建自定义视图
    MyView* view = [[MyView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    //用自定义视图替换系统默认视图
    rootViewController.view = view;
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    self.window.rootViewController = rootViewController;
    
    return YES;
}
@end
#import "MyView.h"

@implementation MyView

- (void)drawRect:(CGRect)rect {

    //填充白色背景
    [[UIColor whiteColor] setFill];
    UIRectFill(rect);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextMoveToPoint(context, 333, 0);
    CGContextAddCurveToPoint(context, 333, 0, 332, 26, 330, 26);
    CGContextAddCurveToPoint(context, 330, 26, 299, 20, 299, 17);
    CGContextAddLineToPoint(context, 296, 17);
    CGContextAddCurveToPoint(context, 296, 17, 296, 19, 291, 19);
    CGContextAddLineToPoint(context, 250, 19);
    CGContextAddCurveToPoint(context, 250, 19, 241, 24, 238, 19);
    CGContextAddCurveToPoint(context, 236, 20, 234, 24, 227, 24);
    CGContextAddCurveToPoint(context, 220, 24, 217, 19, 216, 19);
    CGContextAddCurveToPoint(context, 214, 20, 211, 22, 207, 20);
    CGContextAddCurveToPoint(context, 207, 20, 187, 20, 182, 21);
    CGContextAddLineToPoint(context, 100, 45);
    CGContextAddLineToPoint(context, 97, 46);
    CGContextAddCurveToPoint(context, 97, 46, 86, 71, 64, 72);
    CGContextAddCurveToPoint(context, 42, 74, 26, 56, 23, 48);
    CGContextAddLineToPoint(context, 9, 47);
    CGContextAddCurveToPoint(context, 9, 47, 0, 31, 0, 0);
    CGContextStrokePath(context);

}

@end

void CGContextAddCurveToPoint(

CGContextRef c,//创建CGContext对象(CGContextRef是CGContext的应用类型)

CGFloat cp1x,CGFloat cp1y,//第一控制点

CGFloat cp2x,CGFloat cp2y,//第二控制点

CGFloat x,CGFloat y,//端点

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值