概述
UIProgressView显示某个操作完成的进度(百分比)
UIProgressView
init
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithProgressViewStyle:(UIProgressViewStyle)style; // sets the view height according to the style
appearance
@property(nonatomic) UIProgressViewStyle progressViewStyle; // default is UIProgressViewStyleDefault
@property(nonatomic, strong, nullable) UIColor* progressTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong, nullable) UIColor* trackTintColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong, nullable) UIImage* progressImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
@property(nonatomic, strong, nullable) UIImage* trackImage NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
typedef NS_ENUM(NSInteger, UIProgressViewStyle) {
UIProgressViewStyleDefault, // normal progress bar
UIProgressViewStyleBar __TVOS_PROHIBITED, // for use in a toolbar
};
注意:
- 图像优先,如果设置了图像,颜色被ignored
- UIProgressView的bounds.size.height取决于progressViewStyle,不可定制,UIProgressViewStyleDefault为2,UIProgressViewStyleBar为3
progress
@property(nonatomic) float progress; // 0.0 .. 1.0, default is 0.0. values outside are pinned.
- (void)setProgress:(float)progress animated:(BOOL)animated NS_AVAILABLE_IOS(5_0);
@property(nonatomic, strong, nullable) NSProgress *observedProgress NS_AVAILABLE_IOS(9_0);
注意:
- observedProgress优先,observedProgress默认为nil
- 在observedProgress模式下,UIProgressView animated update progress,即UIProgressView实时从observedProgress获取progress,然后调用setProgress:progress animated:YES