Uiimage for IOS development and learning

Time:2021-7-27

1. Two ways of loading pictures in uiimage

(1) There is a cache (the memory occupied by pictures will always stay in the program), which may cause the program to crash due to a large amount of memory. It can be used when loading a small number of small pictures.

+ (UIImage *)imageNamed:(NSString *)name;

Name is the file name of the picture. PNG pictures do not need a suffix. JPG and other picture formats need a suffix.
(2) No cache (the memory occupied by pictures will be cleared after some specific operations), which is used when loading a large number of pictures

+ (UIImage *)imageWithContentsOfFile:(NSString *)path 
- (id)initWithContentsOfFile:(NSString *)path;

Path is the full path of the picture
For example:

NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:filename ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];

2. Set uiimageveiw fillet

self.iconView.layer.cornerRadius = 8;// Fillet radius 
self.iconView.clipsToBounds = YES;// All parts beyond the fillet are subtracted

[note] uiimageview can also set the highlighted (clicked) picture:

myImageView.highlightedImage = ...

3. Uiimageview frame animation related properties and methods

@property(nonatomic,copy) NSArray *animationImages; 

Sequence frame image array to be played (there are uiimage objects in it, and the pictures in it will be displayed in order)

@property(nonatomic) NSTimeInterval animationDuration;

Duration of frame animation

@property(nonatomic) NSInteger animationRepeatCount; 

The number of times the frame animation is executed (infinite loop by default)

- (void)startAnimating;  //  Start frame animation
- (void)stopAnimating;   //  Stop frame animation
- (BOOL)isAnimating;     //  Is frame animation in progress

Example:
Load a picture in uiview

- (void)viewDidLoad 
{
    [super viewDidLoad];
   
    //Set picture view
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = self.view.frame;
    
    //Load picture
    imageView.image = [UIImage imageNamed:@"myImage.jpg"];
    [self.view addSubview:imageView];
    
}

effect:

Uiimage for IOS development and learning