IOS-UIImageView common usage and multi-image animation playback, iosuiimageview
UIImageView
// Create the object UIImageView * imageView = [[UIImageView alloc] init]; // frame imageView. frame = self. view. bounds; // set the background imageView. backgroundColor = [UIColor greenColor]; // sets the image imageView. image = [UIImage imageNamed: @ "1"]; // The UIViewContentModeScaleToFill with a Scale image may be stretched. The Scale is a proportional UIViewContentModeScaleAspectFit, done, // The image content mode imageView will not be stretched. The following options are available: UIViewContentModeCenter, UIViewContentModeTop, audience, UIViewContentModeLeft, UIViewContentModeRight, audience, UIViewContentModeTopRight, audience, and. contentMode = UIViewContentModeScaleAspectFit; // determines whether to cut unnecessary imageView. clipsToBounds = YES; // create a glass UIToolbar * toolbar = [[UIToolbar alloc] init]; // set the glass size toolbar. frame = imageView. bounds; // set the style toolbar of the glass. barStyle = UIBarStyleBlack; toolbar. alpha = 0.9; [imageView addSubview: toolbar]; // load it to the Controller view [self. view addSubview: imageView];
First and second types of frame
// Create an object // UIImageView * imageView = [[UIImageView alloc] init]; // imageView. image = [UIImage imageNamed: @ "1"]; // frame setting method // The first type // imageView. frame = CGRectMake (0, 0,500,833); // type 2 UIImage * image = [UIImage imageNamed: @ "1"]; imageView. frame = CGRectMake (0, 0, image. size. width, image. size. height); imageView. image = image;
Third
// The third type is UIImage * image = [UIImage imageNamed: @ "1"]; UIImageView * imageView = [[UIImageView alloc] initWithFrame: CGRectMake (0, 0, image. size. width, image. size. height)]; imageView. image = image;
Fourth
// Type 4: UIImageView * imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "1"];
// Modify the location imageView. center = CGPointMake (10, 10); // load it to the Controller view [self. view addSubview: imageView];
Image Retrieval
// Load the image // method 1 // self. imageView. image = [UIImage imageNamed: @ "1"]; // method 2 NSString * path = [[NSBundle mainBundle] pathForResource: @ "1" ofType: @ "jpg"]; self. imageView. image = [UIImage imageWithContentsOfFile: path]; // put it into Assets. path in xcassets, which cannot be obtained. imageWithContentsOfFile: // only imageNamed: // can be obtained from images in the project.
Multiple images form an animation. 1. Load resources.
If you create a real folder, you need to write all the paths when calling the folder. If it is a virtual folder, you do not need
2. How to load the image extracted
-(NSArray *) loadAllImageWithimagePrefix :( NSString *) imagePrefix count :( int) count {NSMutableArray
* Images = [NSMutableArray array]; for (int I = 0; I <count; I ++) {// obtain the image name NSString * imageName = [NSString stringWithFormat: @ "% @ _ % d", imagePrefix, I + 1]; // create a UIImage * image = [UIImage imageNamed: imageName] by name; // load the array [images addObject: image];} // return the image array return images ;}
- (void)viewDidLoad { [super viewDidLoad]; self.useImage = [self loadAllImageWithimagePrefix:@"Prefix" count:250];}How to extract and play an animation
-(Void) playAnimationWithImagesArray :( NSArray *) imagesArray repeatCount :( int) count duration :( float) duration {// sets the playback animation image self. imageView. animationImages = imagesArray; // sets the number of playbacks. 0 indicates unlimited self. imageView. animationRepeatCount = count; // playback duration self. imageView. animationDuration = duration; // playback [self. imageView startAnimating];}