UIKit和Core Graphics绘图——构造路径,阴影以及渐变扩展

这篇博客深入介绍了在UIKit和Core Graphics中如何构造路径,包括画对角线、绘制多个矩形,以及为图形添加阴影效果。同时,还探讨了如何在iOS应用中实现渐变的扩展技术。
摘要由CSDN通过智能技术生成

构造路径


通常,一系列点组合一起构成一个形状,而若干个形状组合在一起可以构造一个路径,路径可以规则也可以不规则,随意组合。通过Core Graphics很容易管理路径。

主要用到的函数或方法:

CGPathCreateMutable() 创建可变路径的方法
CGContextAddPath 将路径加入到上下文中
CGContextDrawPath绘制路径
CGPathRelease 路径也需要释放

用路径画一组对角线


- (void)drawRect:(CGRect)rect
{
    // Drawing code
    [self drawTwoLines];
}

- (void)drawTwoLines
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, screenRect.origin.x, screenRect.origin.y);
    CGPathAddLineToPoint(path, NULL, screenRect.size.width, screenRect.size.height);
    CGPathMoveToPoint(path, NULL, screenRect.size.width, screenRect.origin.y);
    CGPathAddLineToPoint(path, NULL, screenRect.origin.x, screenRect.size.height);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddPath(context, path);
    CGContextSetLineWidth(context, 1.0f);
    [[UIColor blueColor] setStroke]
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值