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