一个 UIProgressView 子类,它可以显示易于定制的 popUpView 中的完成百分比。
如果您需要类似 UISlider 的功能,请参阅 ASValueTrackingSlider。
对于 CocoaPods 用户,只需将 pod 'ASProgressPopUpView'
添加到您的 podfile 中。别忘了,CocoaPods 包含了 try
命令,类型 $ pod try ASProgressPopUpView
在终端中,CocoaPods 将将演示项目下载到临时文件夹并使用 Xcode 打开它。魔法。
如果不使用 CocoaPods,只需将这些文件包括到您的项目中
非常简单。将 UIProgressView 拖动到 Storyboard/nib 中,将其设置类为 ASProgressPopUpView —— 就这样。下面的示例演示了如何自定义外观。
self.progressView.font = [UIFont fontWithName:@"Futura-CondensedExtraBold" size:26];
self.progressView.popUpViewAnimatedColors = @[[UIColor redColor], [UIColor orangeColor], [UIColor greenColor]];
self.progressView.popUpViewCornerRadius = 16.0;
要显示弹出视图,只需调用
[self.progressView showPopUpViewAnimated:YES];
要隐藏
[self.progressView hidePopUpViewAnimated:YES];
与通常使用 UIProgressView 相同的方式更新值,只需更新 progress
属性 self.progressView.progress = 0.31;
。
从 version 0.7.1
开始,支持动画进度方法 - (void)setProgress:(float)progress animated:(BOOL)animated
。当进一步更新进度 > 0.05
时,使用动画形式将会更加平滑。
将您的控制器设置为 dataSource
,然后为要自定义的任何进度值返回 NSStrings。
- (NSString *)progressView:(ASProgressPopUpView *)progressView stringForProgress:(float)progress
{
NSString *s;
if (progress < 0.2) {
s = @"Just starting";
} else if (progress > 0.4 && progress < 0.6) {
s = @"About halfway";
} else if (progress > 0.75 && progress < 1.0) {
s = @"Nearly there";
} else if (progress >= 1.0) {
s = @"Complete";
}
return s;
}
要在UITableView内有效使用,您需要实现<ASProgressPopUpViewDelegate>
协议。如果您在UITableViewCell中嵌入ASProgressPopUpView,popUpView可能会被上面的cell遮挡。代理方法会在popUpView出现之前通知您,以确保您的UITableViewCell渲染在其他cell之上。
与UITableView一起推荐的技术是创建一个实现代理方法的UITableViewCell子类。
@interface ProgressCell : UITableViewCell <ASProgressPopUpViewDelegate>
@property (weak, nonatomic) IBOutlet ASProgressPopUpView *progressView;
@end
@implementation ProgressCell
- (void)awakeFromNib
{
self.progressView.delegate = self;
}
- (void)progressViewWillDisplayPopUpView:(ASProgressPopUpView *)progressView;
{
[self.superview bringSubviewToFront:self];
}
@end