slider进度条 - 绘制圆形
2016-01-24 14:42
316 查看
1.效果图
2.storyboard设置
3.代码实现
1.ViewController.m
#import "ViewController.h"
#import "graphicsView.h"
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UILabel *timerLabel;
@property (weak,nonatomic)IBOutlet
graphicsView *progress;
@property (weak,
nonatomic) IBOutlet
UISlider *slid;
//@property (weak,nonatomic)NSTimer *timer;
@end
@implementation ViewController
- (IBAction)slider:(UISlider *)sender {
//根据进度条的值,改变label的文本显示值
self.timerLabel.text = [NSString
stringWithFormat:@"%.2f%%",sender.value *
100];
//同时将进度条的值传给绘制路径
_progress.press = sender.value;
}
2.graphicsView.h
#import <UIKit/UIKit.h>
@interface graphicsView :
UIView
@property (assign,nonatomic)CGFloat press;
@end
3.graphicsView.m
#import "graphicsView.h"
@implementation graphicsView
-(void)setPress:(CGFloat)press{
_press = press;
[self
setNeedsDisplay];
//drawRect在viewwillApear显示时调用,程序后面要重绘,就要调用setNeedsDisplay方法
}
-(void)drawRect:(CGRect)rect{
CGPoint point =
CGPointMake(self.frame.size.width
* 0.5,
self.frame.size.height *0.5);
//绘制区域
CGFloat radius =
self.frame.size.width *
0.5 - 20;
//绘制半径
CGFloat endA = -M_PI_2 +
2 * M_PI *
_press; //绘制到哪个角度,根据传进来的progress值进行变化
//bezierPathWithArcCenter方法用来绘制圆形路径
UIBezierPath *path = [UIBezierPath
bezierPathWithArcCenter:point radius:radius
startAngle:-M_PI_2
endAngle:endA clockwise:YES];
[[UIColor redColor]set];
//设置绘制线的颜色
[path stroke];
//绘制
}
@end
2.storyboard设置
3.代码实现
1.ViewController.m
#import "ViewController.h"
#import "graphicsView.h"
@interface
ViewController ()
@property (weak,
nonatomic) IBOutlet
UILabel *timerLabel;
@property (weak,nonatomic)IBOutlet
graphicsView *progress;
@property (weak,
nonatomic) IBOutlet
UISlider *slid;
//@property (weak,nonatomic)NSTimer *timer;
@end
@implementation ViewController
- (IBAction)slider:(UISlider *)sender {
//根据进度条的值,改变label的文本显示值
self.timerLabel.text = [NSString
stringWithFormat:@"%.2f%%",sender.value *
100];
//同时将进度条的值传给绘制路径
_progress.press = sender.value;
}
2.graphicsView.h
#import <UIKit/UIKit.h>
@interface graphicsView :
UIView
@property (assign,nonatomic)CGFloat press;
@end
3.graphicsView.m
#import "graphicsView.h"
@implementation graphicsView
-(void)setPress:(CGFloat)press{
_press = press;
[self
setNeedsDisplay];
//drawRect在viewwillApear显示时调用,程序后面要重绘,就要调用setNeedsDisplay方法
}
-(void)drawRect:(CGRect)rect{
CGPoint point =
CGPointMake(self.frame.size.width
* 0.5,
self.frame.size.height *0.5);
//绘制区域
CGFloat radius =
self.frame.size.width *
0.5 - 20;
//绘制半径
CGFloat endA = -M_PI_2 +
2 * M_PI *
_press; //绘制到哪个角度,根据传进来的progress值进行变化
//bezierPathWithArcCenter方法用来绘制圆形路径
UIBezierPath *path = [UIBezierPath
bezierPathWithArcCenter:point radius:radius
startAngle:-M_PI_2
endAngle:endA clockwise:YES];
[[UIColor redColor]set];
//设置绘制线的颜色
[path stroke];
//绘制
}
@end
相关文章推荐
- HDU 1013 Digital Roots
- USACO : Party Lamps dfs 深搜
- PHP+HTML5+ajax 图片上传和图片预览
- Redis源码学习四、字典
- JavaScript学习笔记
- Android之广播(本地广播)
- Android SharedPreferences使用
- Thinking in UML 学习笔记(一)——建立对象模型
- 详解Android中Notification通知提醒
- 欢迎使用CSDN-markdown编辑器
- hadoop WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using b
- Apache Commons 工具类介绍及简单使用
- K-Means的一些想法以及实现
- JS010-DOM
- IO流 文件的切割和合并
- redis集群
- Greedy:Graveyard Design(POJ 2100)
- nil、Nil、NULL与NSNull的区别--备用
- 通过vbscript批量更新excel文档oracle数据源(版本1:connection.refresh方法)
- uva10881 - Piotr's Ants (等效变换)