概述
UIImageView显示UIImage封装的图像
UIImageView
init
- (instancetype)initWithImage:(nullable UIImage *)image;
- (instancetype)initWithImage:(nullable UIImage *)image highlightedImage:(nullable UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);
注意:
- UIImageVIew的bounds初始化为UIImage的size,取size时image优先级大于highlightedImage
state
@property (nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled; // default is NO
@property (nonatomic, getter=isHighlighted) BOOL highlighted NS_AVAILABLE_IOS(3_0); // default is NO
appearance
@property (nullable, nonatomic, strong) UIImage *image; // default is nil
@property (nullable, nonatomic, strong) UIImage *highlightedImage NS_AVAILABLE_IOS(3_0); // default is nil
// When tintColor is non-nil, any template images set on the image view will be colorized with that color.
// The tintColor is inherited through the superview hierarchy. See UIView for more information.
@property (null_resettable, nonatomic, strong) UIColor *tintColor NS_AVAILABLE_IOS(7_0);
注意:
- 如果highlightedImage为nil,用image作为default highlightedImage,反之如果image为nil,不会用highlightedImage作为default image
animation
// these allow a set of images to be animated. the array may contain multiple copies of the same
@property (nullable, nonatomic, copy) NSArray<UIImage *> *animationImages; // The array must contain UIImages. Setting hides the single image. default is nil
@property (nullable, nonatomic, copy) NSArray<UIImage *> *highlightedAnimationImages NS_AVAILABLE_IOS(3_0); // The array must contain UIImages. Setting hides the single image. default is nil
@property (nonatomic) NSTimeInterval animationDuration; // for one cycle of images. default is number of images * 1/30th of a second (i.e. 30 fps)
@property (nonatomic) NSInteger animationRepeatCount; // 0 means infinite (default is 0)
- (void)startAnimating;
- (void)stopAnimating;
- (BOOL)isAnimating;
注意:
- 播放动画时,如果animationImages或highlightedAnimationImages中的UIImage是animated UIImage,只取第一张图片作为帧
- 如果highlightedAnimationImages为nil,用animationImages作为default highlightedAnimationImages,反之如果animationImages为nil,不会用highlightedAnimationImages作为default animationImages
- 播放动画时,如果对应的animationImages为nil(如果highlightedAnimationImages为nil,用animationImages作为default highlightedAnimationImages),播放无效果,用对应的image显示(如果highlightedImage为nil,用image作为default highlightedImage),即highlighted=YES时,显示顺序为highlightedAnimationImages->animationImages->highlightedImage->image,highlighted=NO时,显示顺序为animationImages->image
- 调用startAnimating时,强制从第一帧从头开始播放,不会继续之前的播放进度
- 如果当前处于动画中,此时修改animation状态(animationDuration,animationRepeatCount),立即停止播放动画(相当于调用stopAnimation),修改animation状态时不管新值与旧值是否相同