IOS开发-利用绘图表示进度
来源:互联网 发布:复杂网络画图 编辑:程序博客网 时间:2024/05/16 11:35
(1)创建自定义view。
(2)导入QuartzCore框架
(3)在h文件,定义一个属性,用于接收进度值,最大值是1,最小值是0:
#import <UIKit/UIKit.h>@interface ZCView : UIView@property(nonatomic,assign)CGFloat progress;@end
(4)m文件的代码如下:
#import "ZCView.h"#import <QuartzCore/QuartzCore.h>@interface ZCView ()@property(nonatomic,weak)UILabel *progressLabel;@end@implementation ZCView- (instancetype)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if(self) { CGFloat proX = 0; CGFloat proW = frame.size.width; CGFloat proH = 20; CGFloat proY = (frame.size.height-proH)/2; UILabel *progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(proX, proY, proW, proH)]; [progressLabel setTextAlignment:NSTextAlignmentCenter]; self.progressLabel = progressLabel; [self addSubview:progressLabel]; } return self;}- (void)drawRect:(CGRect)rect { //线宽 CGFloat lineWidth = 5; //半径 CGFloat radius = (rect.size.width-lineWidth*4)/2; //圆心 CGPoint center = CGPointMake(rect.size.width/2, rect.size.width/2); //结束弧度 CGFloat endAngle = -M_PI_2+(_progress*M_PI*2); //路径 UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI_2 endAngle:endAngle clockwise:YES]; [path setLineWidth:lineWidth]; [path stroke];}- (void)setProgress:(CGFloat)progress{ _progress = progress; [self.progressLabel setText:[NSString stringWithFormat:@"%.2f%%",progress*100]]; [self setNeedsDisplay];}@end
传入progress的值就能刷新进度了:
0 0
- IOS开发-利用绘图表示进度
- iOS开发-绘图
- iOS开发---绘图
- iOS开发 - Quartz2D绘图
- iOS开发 - Quartz2D绘图
- iOS开发 高级绘图
- iOS开发 - Quartz2D绘图
- ios开发ASIHTTPRequest-进度追踪
- ios开发ASIHTTPRequest-进度追踪
- iOS开发ASIHTTPRequest进度追踪
- iOS开发ASIHTTPRequest进度追踪
- iOS开发ASIHTTPRequest进度追踪
- iOS开发ASIHTTPRequest进度追踪
- iOS开发ASIHTTPRequest进度追踪
- iOS开发UI-利用Quartz2D 实现基本绘图(画三角形、矩形、圆、圆弧)
- iOS开发封装篇-利用CAShapeLayer和绘图封装一个动画按钮
- iOS开发封装篇-利用绘图封装一个可以涂鸦的view
- IOS开发之—绘图
- Mac&iOS Socket
- Android ViewPager 循环轮播
- Top K Frequent Elements
- 源码解析ConcurrentHashMap
- spring容器加载完毕做一件事情(利用ContextRefreshedEvent事件)
- IOS开发-利用绘图表示进度
- JS面向对象定义多个属性--object.defineProperties()方法
- [从头学数学] 第214节 带着计算机去高考(六)
- 记录阿里云被肉鸡的破解方法
- 验证(Javascript和正则表达式)
- 多个glBindBuffer和glDrawXXX 需要glBindVertexArray VAO指定
- iOS 一切皆Socket
- C++第六次实验
- socket(UDP)