(material source) Cat learn iOS (29) UI quartz2d Custom Download controls

Source: Internet
Author: User

Cat Share, must boutique

Material code Address: http://download.csdn.net/detail/u013357243/8640353
Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243?viewmode=contents

Effect

Code NYPROGRESSVIEW.M
////NYPROGRESSVIEW.M//Download progress bar////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 lazy Loading of/**label * *-(UILabel*) label{if(_label = =Nil) {UILabel*label = [[UILabelAlloc]initwithframe:cgrectmake (0,0, -, -)]; Label. TextAlignment= Nstextalignmentcenter; [ SelfAddsubview:label];    _label = label; }return_label;} -(void) Setprogress: (CGFloat) progress{_progress = progress; Self. Label. Text= [NSStringstringwithformat:@"%.2f%%", progress* -];//Redraw make a redraw mark on the view and call DrawRect the next time the screen refreshes. [ SelfSetneedsdisplay];} - (ID) initWithFrame: (CGRect) frame{ Self= [SuperInitwithframe:frame];if( Self) {//initialization code}return  Self;}/** Painting When the view is displayed, the default is to call only one solution://Redraw a redraw mark on the view and call DrawRect the next time the screen refreshes. [Self setneedsdisplay]; */- (void) DrawRect: (CGRect) rect{//1: Get ContextCgcontextref CTX = Uigraphicsgetcurrentcontext ();//2: Stitching path    / * We need to draw a circle chart * /    CgpointCenter = Cgpointmake ( -, -);//Center    CGFloatRadius = +;//Radius    CGFloatStarta =-m_pi_2;//Starting angle    CGFloatEnda =-m_pi_2 + _progress * M_PI *2;//End angle. Uibezierpath *path = [Uibezierpath bezierpathwitharccenter:center radius:radius Startangle:starta EndAngle:endA Clockwise:YES];//clockwise clockwise direction.     ///3: Add the path to the context. Cgcontextaddpath (CTX, Path. Cgpath);//Set color to red[[UicolorRedcolor] set];//Set the width of the lineCgcontextsetlinewidth (CTX,Ten);//Set the styles on both sides to rounded cornersCgcontextsetlinecap (Ctx,kcglinecapround);///4: Renders the context to the view. Cgcontextstrokepath (CTX);}@end
Nyviewcontroller.m
////NYVIEWCONTROLLER.M//Download progress bar////Created by Apple on 15-4-27.//Copyright (c) 2015 Znycat. All rights reserved.//#Import "NYViewController.h"#Import "NYProgressView.h"@interfaceNyviewcontroller ()@property(Weak, nonatomic) Iboutlet Nyprogressview *progressview;@end@implementationNyviewcontroller/** events that occur with sliding sliders * /-(Ibaction) ValueChange: (UISlider *) Sender {NSLog (@"%f", Sender.value); _progressview.progress = Sender.value;} - (void) viewdidload{[SuperViewdidload];additional setup after loading the view, typically from a nib.}- (void) didreceivememorywarning{[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}@end

(material source) Cat learn iOS (29) UI quartz2d Custom Download controls

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.