iOS 圆形进度的实现和封装 两种样式
来源:互联网 发布:centos无法用ssh指令 编辑:程序博客网 时间:2024/06/07 08:43
效果图:
主要代码:
第一种样式:不完全圆进度条
IncompleteHollowCircleProgress.h
#import <UIKit/UIKit.h>@interface IncompleteHollowCircleProgress : UIView@property(nonatomic)CGFloat totalProgress;@property(nonatomic)CGFloat progress;@property(nonatomic)CGFloat lineWidth;@property(nonatomic)BOOL isSetLineCapRound;@property(nonatomic,strong)UIColor *bgColor;@property(nonatomic,strong)UIColor *progressColor;@end
IncompleteHollowCircleProgress.m
#import "IncompleteHollowCircleProgress.h"@implementation IncompleteHollowCircleProgress{ CGFloat radius;}- (void)awakeFromNib { [super awakeFromNib]; [self commonInit];}-(instancetype)init { if (self = [super init]) { [self commonInit]; } return self;}- (instancetype)initWithCoder:(NSCoder *)coder{ self = [super initWithCoder:coder]; if (self) { [self commonInit]; } return self;}-(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self commonInit]; } return self;}-(void)commonInit{ self.totalProgress = 100; self.progress = 90; self.lineWidth = 5; self.bgColor = [UIColor lightGrayColor]; self.progressColor = [UIColor yellowColor]; self.isSetLineCapRound = YES;}- (void)drawRect:(CGRect)rect { CGFloat width = rect.size.width; CGFloat height = rect.size.height; if (width > height) { radius = (height-self.lineWidth)/2; }else { radius = (width-self.lineWidth)/2; } CGPoint center = CGPointMake(width/2, height/2); [self.bgColor set]; UIBezierPath *path = [UIBezierPath new]; path.lineWidth = self.lineWidth; path.lineCapStyle = kCGLineCapRound; [path addArcWithCenter:center radius:radius startAngle:M_PI_2+M_PI_4 endAngle:M_PI_2-M_PI_4 clockwise:YES]; [path stroke]; [path closePath]; CGFloat perPercent = self.progress/self.totalProgress; [self.progressColor set]; UIBezierPath *path2 = [UIBezierPath new]; path2.lineWidth = self.lineWidth; if (self.isSetLineCapRound) { path2.lineCapStyle = kCGLineCapRound; } [path2 addArcWithCenter:center radius:radius startAngle:M_PI_2+M_PI_4 endAngle:M_PI_2+M_PI_4+(perPercent*(2*M_PI-M_PI_2)) clockwise:YES]; [path2 stroke]; [path2 closePath];}@end
第二种样式:完全圆进度条
HollowCircleProgress.h
#import <UIKit/UIKit.h>@interface HollowCircleProgress : UIView@property(nonatomic)CGFloat totalProgress;@property(nonatomic)CGFloat progress;@property(nonatomic)CGFloat lineWidth;@property(nonatomic)BOOL isSetLineCapRound;@property(nonatomic,strong)UIColor *bgColor;@property(nonatomic,strong)UIColor *progressColor;@endHollowCircleProgress.m
#import "HollowCircleProgress.h"@implementation HollowCircleProgress { CGFloat radius;}- (void)awakeFromNib { [super awakeFromNib]; [self commonInit];}-(instancetype)init { if (self = [super init]) { [self commonInit]; } return self;}- (instancetype)initWithCoder:(NSCoder *)coder{ self = [super initWithCoder:coder]; if (self) { [self commonInit]; } return self;}-(instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self commonInit]; } return self;}-(void)commonInit{ self.totalProgress = 100; self.progress = 60; self.lineWidth = 20; self.bgColor = [UIColor lightGrayColor]; self.progressColor = [UIColor redColor]; self.isSetLineCapRound = NO;}- (void)drawRect:(CGRect)rect { CGFloat width = rect.size.width; CGFloat height = rect.size.height; if (width > height) { radius = (height-self.lineWidth)/2; }else { radius = (width-self.lineWidth)/2; } CGPoint center = CGPointMake(width/2, height/2); [self.bgColor set]; UIBezierPath *path = [UIBezierPath new]; path.lineWidth = self.lineWidth; [path addArcWithCenter:center radius:radius startAngle:0 endAngle:2*M_PI clockwise:YES]; [path stroke]; [path closePath]; UIBezierPath *path2 = [UIBezierPath new]; CGFloat perPercent = self.progress/self.totalProgress; [self.progressColor set]; path2.lineWidth = self.lineWidth; if (self.isSetLineCapRound) { path2.lineCapStyle = kCGLineCapRound; } [path2 addArcWithCenter:center radius:radius startAngle:M_PI+M_PI_2 endAngle:M_PI+M_PI_2 - (perPercent*2*M_PI) clockwise:NO]; [path2 stroke]; [path2 closePath]; }@end
阅读全文
0 0
- iOS 圆形进度的实现和封装 两种样式
- 2种方式实现带进度的圆形进度条
- 引出序号的圆形两项样式
- 各种加载和圆形进度的效果
- ProgressBar的圆形进度和水平进度的使用
- DialogFragment实现带数字倒计时和小圆点进度的圆形进度条
- Android CircleProgress:可自由定制实现各种样式圆形加载进度
- 自定义实现简单的ios风格的弹窗加载进度框,一步步走向封装
- 豆瓣FM歌曲播放圆形进度的实现
- Android高级UI ProgressBar实现各种效果的圆形进度
- 微信小程序实现美美的虚线圆形进度圈
- iOS用AFNetWorking实现头像的上传和进度显示
- iOS:圆形头像和菱形头像的实现
- 三角形、梯形和圆形的类封装
- 自定义圆形进度ProgressBar的颜色和图片
- 两种方式实现圆形图片
- android两种方式实现圆形图片
- Android 两种方式实现圆形头像
- 如何把MyEclipse中的web项目导入到Eclipse中运行
- Ubuntu16.04火狐浏览器问题汇总
- RAC 管理(crs_stat、crsctl、srvctl)
- IMP
- IDEA gradle 搭建SSM框架(Mysql数据库)
- iOS 圆形进度的实现和封装 两种样式
- 理解OAuth 2.0
- 安装CDH找不到java_home的错误
- ace-admin图标使用
- HTTPs SSL CA
- 当前的安全设置不允许从该位置下载文件。 的解决办法
- android studio 翻译插件,可以将英文翻译为中文
- 【oracle语法】-for update 与 rowid
- 进程间的八种通信方式