2014-11-01 81 views
0

我想製作一個自定義的UIProgressView填充圖像是耐克旋風。我試圖遵循一些教程,但是無處可去。自定義UIProgressView與圖像

我目前的做法:

使swoosh內部透明和周圍黑色。 然後放一個大的UIProgressView。 因爲旋風的中間部分是透明的,所以看起來旋風正在充滿。

但是,修改進度條的高度已被證明是一種痛苦,因爲它以一種奇怪的方式混淆了寬度......並且難以將耐克與進度條對齊以獲得響應。

有沒有其他想法或圖書館?

感謝

+0

創建自己的控件,繪製旋風,並根據需要填寫入。 – rmaddy 2014-11-01 23:28:04

回答

0

我的建議:

繪製第二圖像編程應用作爲對你的「旋風」形象口罩,然後重複這個循環。

例如,填補圖像由左(右面膜吧)

{ 
//existing variables 

IBOutlet UIImageView *swooshView; 


} 

-(UIImage *)maskImageOfSize:(CGSize)size filledTo:(CGFloat)percentage{ 

UIGraphicsBeginImageContextWithOptions (size, NO, 0.0); 
CGContextRef context = UIGraphicsGetCurrentContext(); 


CGContextSetFillColourWithColour (context, [UIColor blackColor].CGColor); 

CGRect fillRect = CGRectZero; 
fillRect.size.height = size.height; 
fillRect.size.width = size.width * percentage/100.0; 
fillRect.origin.x = (size.width - fillRect.size.width); 

CGContextFillRect(context, fillRect); 

UIImage *result = UIGraphicsGetImageFromImageContext(); 
UIGraphicsEndImageContext(); 

return result; 
} 



-(void)fillSwooshToPercentage:(CGFloat)percentage{ 

percentage = ((CGFloat) fmaxf (0.0 , (fminf (100.0, (float) percentage))); 
// just policing a 'floor' and 'ceiling'... 
swooshView.layer.mask = [self maskImageOfSize:self.swoosh.bounds.size filledTo:percentage]; 

}