IOS第16天(2,Quartz2D下载进度条)
2015-09-01 17:05
423 查看
*************自定义下载的view的方法
*******监听
#import "HMProgressView.h" @interface HMProgressView() @property (nonatomic, weak) UILabel *label; @end @implementation HMProgressView - (UILabel *)label { if (_label == nil) { UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; label.textAlignment = NSTextAlignmentCenter; [self addSubview:label]; _label = label; } return _label; } - (void)setProgress:(CGFloat)progress { _progress = progress; self.label.text = [NSString stringWithFormat:@"%.2f%%",progress * 100]; //文字 // [self drawRect:self.bounds]; // 重新绘制 // 在view上做一个重绘的标记,当下次屏幕刷新的时候,就会调用drawRect. [self setNeedsDisplay]; } // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. // 当视图显示的时候会调用 默认只会调用一次 - (void)drawRect:(CGRect)rect { // Drawing code // 1.获取上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); // 2.拼接路径 CGPoint center = CGPointMake(50, 50); CGFloat radius = 50 - 2; CGFloat startA = -M_PI_2; CGFloat endA = -M_PI_2 + _progress * M_PI * 2; UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES]; // 3.把路径添加到上下文 CGContextAddPath(ctx, path.CGPath); // 4.把上下文渲染到视图 CGContextStrokePath(ctx); } @end
*******监听
#import "HMViewController.h" #import "HMProgressView.h" @interface HMViewController () @property (weak, nonatomic) IBOutlet HMProgressView *progressView; //自定义的view @end @implementation HMViewController - (IBAction)valueChange:(UISlider *)sender { _progressView.progress = sender.value; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- 14.IOS中系统唯一标识ID
- iOS KVC,KVO
- 4.极光推送解释的iOS本地通知
- 5.iOS 7 Background Remote Notification
- 2.iOS苹果推送-一些示例代码和注意的问题
- 1.iOS中的系统通知 自定义推送声音
- IOS开发-视频,音频,录音简单总结
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- IOS中nil/Nil/NULL的区别
- iOS-Quartz2D绘图的基础用法总结
- iOS中socket的使用
- iOS 设置导航栏 Navigationbar相关信息
- IOS-添加分段控件SegmentControl
- IOS时间与日期处理
- iOS读取本地txt文件为乱码的解决方法
- iOS 软件中所有动画突然不能正常显示(系统自带的动画也成了一闪而过)
- ios 用NSUserDefaults做本地化搜索记录
- 苹果开发 笔记(68)MBProgressHUD
- iOS开发日记13-原生二维码的扫描和生成
- iOS GCD使用指南