矩阵操作

来源:互联网 发布:淘宝怎么修改送货时间 编辑:程序博客网 时间:2024/05/21 15:17
  • (void)drawRect:(CGRect)rect{
    // 1.获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 注意:上下文矩阵操作一定放在你的路径之前
    // 平移上下文
    CGContextTranslateCTM(ctx, 50, 100);
    // 旋转上下文
    CGContextRotateCTM(ctx, M_PI_4);
    // 缩放上下文
    CGContextScaleCTM(ctx, 0.5, 1.2);

    // 2.拼接路径
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(-50, -100, 150, 200)];
    // 3.把路径添加到上下文
    CGContextAddPath(ctx, path.CGPath);
    [[UIColor yellowColor] set];
    // 4.渲染
    CGContextFillPath(ctx);

}

0 0
原创粉丝点击