国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

通過布賽爾曲線以及CAShapeLayer的strokeStart、strokeEnd屬性來實現(xiàn)一個圓形進(jìn)度條

2019-11-14 19:20:24
字體:
供稿:網(wǎng)友
#import <UIKit/UIKit.h>@interface CirclePRogressView : UIView/**起始值(0-1)*/@property(nonatomic,assign)CGFloat fstartValue;/**邊框?qū)挾?/span>*/@property(nonatomic,assign)CGFloat flineWidth;/**線條顏色*/@property(nonatomic,strong)UIColor *lineColor;/**變化的值*/@property(nonatomic,assign)CGFloat fvalue;@end#import "CircleProgressView.h"@interface CircleProgressView (){    CAShapeLayer *_shapeLayer;}@end@implementation CircleProgressView@synthesize fstartValue=_fstartValue;@synthesize flineWidth=_flineWidth;@synthesize lineColor=_lineColor;@synthesize fvalue=_fvalue;- (instancetype)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self)    {        /**創(chuàng)建帶形狀的圖層*/        _shapeLayer=[CAShapeLayer layer];        _shapeLayer.frame     = self.bounds;        _shapeLayer.strokeEnd = 0.f;                /*創(chuàng)建布賽爾曲線*/        UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:self.bounds];                /**把圖層和不塞爾曲線通過path進(jìn)行關(guān)聯(lián)*/        _shapeLayer.path   = path.CGPath;                /**設(shè)置圖層的填充顏色、寬度、邊框顏色*/        _shapeLayer.fillColor   = [UIColor clearColor].CGColor;        _shapeLayer.lineWidth   = 1.0f;        _shapeLayer.strokeColor = [UIColor redColor].CGColor;                [self.layer addSublayer:_shapeLayer];    }    return self;}/** *  @brief  重寫fstartValue的setter方法 *  @param fstartValue  設(shè)置圓形strokeStart起始值 *  @since */- (void)setFstartValue:(CGFloat)fstartValue{    _fstartValue          = fstartValue;    _shapeLayer.strokeStart = fstartValue;    }- (CGFloat)fstartValue{    return _fstartValue;}/** *  @brief  重寫flineWidth的setter方法 *  @param flineWidth  設(shè)置圓形邊框?qū)挾?*  @since */- (void)setFlineWidth:(CGFloat)flineWidth{    _flineWidth           = flineWidth;    _shapeLayer.lineWidth = flineWidth;}/** *  @brief  重寫lineColor的setter方法 *  @param lineColor  設(shè)置圓形邊框顏色 *  @since */- (void)setLineColor:(UIColor *)lineColor{    _lineColor              = lineColor;    _shapeLayer.strokeColor = lineColor.CGColor;}- (UIColor *)lineColor{    return _lineColor;}/** *  @brief  重寫fvalue的setter方法 *  @param lineColor  設(shè)置圓形的strokeEnd值 *  @since */- (void)setFvalue:(CGFloat)fvalue{    _fvalue                = fvalue;    _shapeLayer.strokeEnd = fvalue;}- (CGFloat)fvalue{    return _fvalue;}@end#import "ViewController.h"#import "CircleProgressView.h"@interface ViewController (){    CircleProgressView *progress;}@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];        progress             = [[CircleProgressView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];    progress.center      = self.view.center;    progress.lineColor   = [UIColor redColor];    progress.flineWidth  = 1.0f;    progress.fstartValue = 0;    [self.view addSubview:progress];    [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(circleAnimation) userInfo:nil repeats:YES];    }- (void)circleAnimation{    progress.fvalue = arc4random()%100/100.f;}- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];   }@end


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 黄陵县| 资溪县| 嘉兴市| 安溪县| 九台市| 南乐县| 台南市| 偏关县| 汝州市| 黄陵县| 浑源县| 涪陵区| 呼和浩特市| 吕梁市| 文水县| 商洛市| 佛冈县| 清新县| 长海县| 台中市| 伊金霍洛旗| 丹凤县| 桐城市| 吉木萨尔县| 小金县| 五台县| 土默特左旗| 尼勒克县| 大余县| 镇康县| 花莲县| 乌兰县| 津市市| 云南省| 霍林郭勒市| 高平市| 阿荣旗| 偃师市| 龙海市| 肥东县| 双流县|