2016-07-22 52 views
0

如何使用默認progresView製作progressview,就像在應用商店中一樣?Objective-C:圓形進度視圖

如圖片如下圖所示:

enter image description here

+1

請看鏈接https://github.com/PavelKatunin/DownloadButton希望這個幫助 – iSashok

+0

看到這個https://github.com/UrbanApps/UAProgressView –

+0

你需要一個自定義控件。你不能用UIProgressView來做到這一點。 – jp2g

回答

2

您可以使用此代碼,我已經畫了圓圈爲您服務。

- (void)viewDidLoad { 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

CAShapeLayer* outsideShapeLayer = [[CAShapeLayer alloc] init]; 
outsideShapeLayer.fillColor = [[UIColor clearColor] CGColor]; 
outsideShapeLayer.frame = CGRectMake(100, 100, 100, 100); 
outsideShapeLayer.path = [[UIBezierPath bezierPathWithOvalInRect:outsideShapeLayer.bounds] CGPath]; 
outsideShapeLayer.lineWidth = 1; 
outsideShapeLayer.strokeColor = [[UIColor blueColor] CGColor]; 
[self.view.layer addSublayer:outsideShapeLayer]; 


CAShapeLayer* shapeLayer = [[CAShapeLayer alloc] init]; 
shapeLayer.fillColor = [[UIColor clearColor] CGColor]; 
shapeLayer.frame = CGRectMake(102.5, 102.5, 95, 95); 
shapeLayer.path = [[UIBezierPath bezierPathWithOvalInRect:shapeLayer.bounds] CGPath]; 
shapeLayer.lineWidth = 5; 
shapeLayer.strokeColor = [[UIColor blueColor] CGColor]; 
shapeLayer.strokeStart = 0; 
shapeLayer.strokeEnd = 0.75f; 
[self.view.layer addSublayer:shapeLayer]; 
} 

希望它能幫助你。

+0

謝謝,但我怎麼可以使用UIProgressView這個圈子? – user214155

+0

無論您使用UIProgressView還是CustomProgressView(循環版),您都必須有計時器或API來控制進度,如果要使用它們,只需確保它們由同一控制器控制即可。 –

+0

如果您對動畫有一些疑問,只需更改shapeLayer的strokeEnd屬性。 –