iOS basic control UIImageView

Keywords: Attribute

UIImageView introduction

UIImageView is a container for placing pictures. In the development of app, if you want to show pictures, you need to use UIImageView as a control. Here's how to use

UIImageView creation

UIImageView and UILabel are inherited from UIView, so the creation of UIImageView is the same as UIView.

    //UIImageView Creation 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 200)];

Using command + left mouse button to view the header file of UIImageView, you can see that there are two creation methods besides those inherited from UIView

    - (instancetype)initWithImage:(nullable UIImage *)image;
    - (instancetype)initWithImage:(nullable UIImage *)image highlightedImage:(nullable UIImage *)highlightedImage NS_AVAILABLE_IOS(3_0);

No matter what kind of creation method, it needs to be clear that the control is used to show pictures. So location size and image are key. Here are some common properties and methods of UIImageView

Common properties of UIImageView

1. image property
The image property is a picture, that is, a picture loaded on UIImageView. Through the setting of this property, pictures can be displayed on the interface.

    //to imageView Set up the picture here UIImage Class to give image Attribute assignment UIImage Class giving image There are two common methods of assignment
    //+ (nullable UIImage *)imageNamed:(NSString *)name;                Assign with picture name
    //+ (nullable UIImage *)imageWithContentsOfFile:(NSString *)path;   Use image address assignment
    imageView.image = [UIImage imageNamed:@"image"];

Other common properties of UIImageView are inherited from UIView. I will not repeat here. You can see some other properties and methods in the header file of UIImageView:

@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;
#if UIKIT_DEFINE_AS_PROPERTIES
@property(nonatomic, readonly, getter=isAnimating) BOOL animating;
#else
- (BOOL)isAnimating;

These are animation settings related to pictures, which are not recorded here first, and are recorded uniformly when writing about animation later.

Posted by Dan06 on Wed, 01 Jan 2020 04:07:11 -0800