IOS 自定义控件之UIActivityIndicatorView

本文探讨了如何自定义UIActivityIndicator,通过讲解实现过程,介绍CAShapeLayer和CAGradientLayer的使用,旨在提供自定义控件的思路。文章包含一个简单的demo展示,代码仅供学习,不建议直接应用。
摘要由CSDN通过智能技术生成

原创blog,转载请注明出处
blog.csdn.net/hello_hwc

前言
这个系列的本身不是为了写一些东西让读者拿过去就直接可以用的。过段时间我会在github上传一些拿去就可以用的。这个系列的本身是希望抛砖引玉,提供一些自定义控件的思路。
本文的内容

  • 阐述了实现自定义UIActivityIndicator的过程

希望通过本文,读者能够学会

  • CAShapeLayer的简单使用
  • CAGradientLayer的简单使用
  • 自定义控件的一些思路

    一 demo效果
    这里写图片描述

二 实现的过程

  1. 用_shapeLayer定义环形路径
_shapeLayer = [CAShapeLayer layer];
        _shapeLayer.bounds = CGRectMake(0, 0, 100,100);
        _shapeLayer.position = CGPointMake(50,50);
        _shapeLayer.strokeColor = [UIColor blueColor].CGColor;
        _shapeLayer.fillColor = [UIColor clearColor].CGColor;
        CGMutablePathRef path = CGPathCreateMutable();
        _shapeLayer.lineWidth = 5.0;
//        _shapeLayer.backgroundColor = [UIColor purpleColor].CGColor;
        CGPathAddArc(path, nil,50, 50,45,0,2*M_PI,YES);
        _shapeLayer.path = path;

2 用CAGradientLayer定义渐变,用上文的环形路径去截取。

 _indicatorLayer = [[CAGradientLayer alloc] init];
        _indicatorLayer.bounds = CGRectMake(0, 0, 100,100);
        _indicatorLayer.position = CGPointMake(50,50);
        _indicatorLayer.colors = @[(id)[UIColor blueColor].CGColor,
                                   (id)[UIColor greenColor].CGColor,
                                   (id)[UIColor blueColor].CGColor];
        _indicatorLayer.locations  = @[@(0.25), @(0.5), @(0.75)];
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值