进度条的自定义
来源:互联网 发布:电脑网络枪战游戏大全 编辑:程序博客网 时间:2024/06/03 22:46
自定义环形进度条
思路:
1.利用
直接附上代码
test.h/test.m
MyProgressView.h/MyProgressView.m
#import <UIKit/UIKit.h>@interface test : UIView@property(nonatomic, assign)float progressRate;@end
#import "test.h"#import <QuartzCore/QuartzCore.h>@implementation test-(void)drawRect:(CGRect)rect{ CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor (context, 1, 0, 0, 1.0);//设置填充颜色 //画扇形并填充颜 UIColor*aColor = [UIColor lightGrayColor]; CGContextSetFillColorWithColor(context, aColor.CGColor);//填充颜色 CGContextMoveToPoint(context, rect.size.width*0.5, rect.size.width*0.5); CGContextAddArc(context, rect.size.width*0.5, rect.size.width*0.5, rect.size.width*0.5, -0.5*M_PI, -0.5*M_PI+self.progressRate*2*M_PI, 0); CGContextClosePath(context); CGContextDrawPath(context, kCGPathFill); //绘制路径加填充 /*官方文档参数说明 void CGContextAddArc ( CGContextRef c, CGFloat x, CGFloat y, CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise ); Parameters: c-A graphics context. x-The x-value, in user space coordinates, for the center of the arc. y-The y-value, in user space coordinates, for the center of the arc. radius-The radius of the arc, in user space coordinates. startAngle-The angle to the starting point of the arc, measured in radians from the positive x-axis. endAngle-The angle to the end point of the arc, measured in radians from the positive x-axis. clockwise-Specify 1 to create a clockwise arc or 0 to create a counterclockwise arc */}@end
#import <UIKit/UIKit.h>#import "test.h"@interface MyProgressView : UIView@property(nonatomic, strong)test *imgOutSide;@property(nonatomic, strong)UIView *imgInner;-(void)animatProgress:(float)progress;-(void)addProgressToView:(UIView *)view;@end
“`
import “MyProgressView.h”
import “common.h”
@implementation MyProgressView
-(id)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
_imgInner = [self imgViewWithFrame:CGRectMake((frame.size.width-60)*0.5, (frame.size.height-60)*0.5, 60, 60)]; _imgOutSide = [[test alloc]initWithFrame:CGRectMake(0, 0, 60, 60)]; _imgOutSide.backgroundColor= [UIColor whiteColor]; //遮盖 UIView *coverView = [self imgViewWithFrame:CGRectMake(5, 5, 50, 50)]; coverView.backgroundColor = kColor(216, 216, 216); [self.imgInner addSubview:self.imgOutSide]; [self.imgInner addSubview:coverView]; [self addSubview:self.imgInner];}return self;
}
-(void)addProgressToView:(UIView *)view
{
[view addSubview:self];
}
-(UIView*)imgViewWithFrame:(CGRect)frame
{
UIView *imgView = [[UIView alloc]initWithFrame:frame];
imgView.layer.cornerRadius = frame.size.width*0.5;imgView.clipsToBounds = YES;imgView.layer.borderColor = [UIColor grayColor].CGColor;imgView.layer.borderWidth = 2.0f;return imgView;
}
-(void)animatProgress:(float)progress
{
self.imgOutSide.progressRate = progress;[self.imgOutSide setNeedsDisplay];
}
“`
0 0
- 自定义的圆形进度条
- 进度条的自定义
- 自定义漂亮的进度条
- 自定义简单的进度条
- 自定义漂亮的圆形进度条
- 自定义漂亮的圆形进度条
- cocos2dx 自定义进度条的实现!
- 简单的自定义水平进度条
- 自定义进度条ProgressBar的实现
- 一个自定义的圆形进度条
- 自定义进度条的颜色大小
- Android自定义的圆形进度条
- 安卓 进度条 的自定义
- 自定义的环形进度条样式
- 慕课上学习的自定义进度条
- 双层叠加的自定义进度条
- android 自定义进度条的实现
- 自定义带进度条的WebView
- SAS 打分
- apache vhost 多域名
- 自定义ScrollView实现下拉刷新
- System property 'opennms.library.jicmp' 解决
- Redis持久化方案详解
- 进度条的自定义
- HDOJ 1175 连连看(BFS)
- linux andorid.mk文件解析
- CALayer # 02
- hdu 5365 Run(几何)
- BDF2-JAVA代码以及view页面获取当前登录用户的信息
- form表单的对象
- 九度 Online Judge 算法 刷题 题目1034:寻找大富翁
- STM32中断