(素材源碼)貓貓學IOS(二十九)UI之Quartz2D自訂下載控制項

來源:互聯網
上載者:User

標籤:自訂   源碼   下載   ui   效果   

貓貓分享,必須精品

素材代碼地址:http://download.csdn.net/detail/u013357243/8640353
原創文章,歡迎轉載。轉載請註明:翟乃玉的部落格
地址:http://blog.csdn.net/u013357243?viewmode=contents

效果

代碼NYProgressView.m
////  NYProgressView.m//  下載進度條////  Created by apple on 15-4-27.//  Copyright (c) 2015年 znycat. All rights reserved.//#import "NYProgressView.h"@interface NYProgressView()@property (nonatomic,weak) UILabel *label;@end@implementation NYProgressView/**label的懶載入*/-(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];    //重新繪製 在view上做一個重繪標記,當下次螢幕重新整理的時候,調用drawRect。    [self setNeedsDisplay];}- (id)initWithFrame:(CGRect)frame{    self = [super initWithFrame:frame];    if (self) {        // Initialization code    }    return self;}/**畫畫 當視圖顯示的時候,預設只調用一次 解決辦法://重新繪製 在view上做一個重繪標記,當下次螢幕重新整理的時候,調用drawRect。 [self setNeedsDisplay]; */- (void)drawRect:(CGRect)rect{    // 1:擷取上下文    CGContextRef ctx = UIGraphicsGetCurrentContext();    // 2:拼接路徑    /*我們需要畫一個圓圖*/    CGPoint center = CGPointMake(50, 50);//圓心    CGFloat radius = 43;//半徑    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];    //clockwise 順時針方向。    //3:把路徑添加到上下文。    CGContextAddPath(ctx, path.CGPath);    //設定顏色為紅色    [[UIColor redColor] set];    //設定線條的寬度    CGContextSetLineWidth(ctx, 10);    //設定兩端的樣式為圓角    CGContextSetLineCap(ctx,kCGLineCapRound);    //4:把上下文渲染到視圖。    CGContextStrokePath(ctx);}@end
NYViewController.m
////  NYViewController.m//  下載進度條////  Created by apple on 15-4-27.//  Copyright (c) 2015年 znycat. All rights reserved.//#import "NYViewController.h"#import "NYProgressView.h"@interface NYViewController ()@property (weak, nonatomic) IBOutlet NYProgressView *progressView;@end@implementation NYViewController/**滑動slider發生的事件*/- (IBAction)valueChange:(UISlider *)sender {    NSLog(@"%f",sender.value);    _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

(素材源碼)貓貓學IOS(二十九)UI之Quartz2D自訂下載控制項

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.