//
Viewcontroller.m
Uiimageview detailed
//
Created by Big Huan on 16/1/20.
COPYRIGHT©2016 year BJSXT. All rights reserved.
//
#import "ViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
[Self saveimage];
NSData * data = [NSData datawithcontentsofurl:[nsurl urlwithstring:@ "http://pic2.ooopic.com/01/03/51/ 25b1ooopic19.jpg "];
UIImage * image = [UIImage imagewithdata:data];
Uiimageview * ImageView = [[Uiimageview alloc] initWithFrame:self.view.frame];
Imageview.image = image;
[Self.view Addsubview:imageview];
}
-(void) SaveImage {
NSString * Path = [[NSBundle mainbundle] pathforresource:@ "image" oftype:@ "data"];
NSData * data = [NSData Datawithcontentsoffile:path];
UIImage * image = [UIImage imagewithdata:data];
Uiimageview * ImageView = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 200, 200)];
Imageview.image = image;
[Self.view Addsubview:imageview];
NSString * LocalPath = @ "/users/dahuan/desktop/123.data";
NSData * Localdata = uiimagepngrepresentation (image);
The quality of param2 pictures
NSData * Localdata = uiimagejpegrepresentation (image, 0.5);
[Localdata Writetofile:localpath Atomically:yes];
}
-(void) Createimageview {
Uiimageview-uiimage
//
1, Imagenamed: Method
Imagenamed: It's a class method of uiimage, it does things a little bit more than we see. Its loading process is as follows:
A. The system goes back to check the system cache for an image of that name, and returns if it exists.
B. If the image of the name does not exist in the system cache, it will be loaded into the cache before the object is returned.
Observing the above operation we find that the system caches the images we use imagenamed: method to load, and the system automatically caches them for us. This mechanism is suitable for loads that are frequently used for interface mapping, but it is best not to use this method if we need to load some disposable images frequently in a short time.
//
2, Imagewithcontentsoffile: and Imagewithdata: Methods
The image is loaded into the program by the system in data mode. When you don't need to reuse the image, or if you need to store the image as data in a database, or if you want to download a large image over the network, try to load the image using Imagewithdata.
UIImage * Image1 = [UIImage imagenamed:@ "baby.jpg"];
NSString * Path = [[NSBundle mainbundle] pathforresource:@ "Baby" oftype:@ "jpg"];
UIImage * Image1 = [UIImage Imagewithcontentsoffile:path];
Uiimageview * ImageView = [[Uiimageview alloc] initwithimage:image1];
Imageview.frame = CGRectMake (A, image1.size.width, image1.size.height);
[Self.view Addsubview:imageview];
}
-(void) Endfile {
Png,pdf do not need to add a suffix name
Add suffix names such as jpg
UIImage * image = [UIImage imagenamed:@ "fengjing"];
Uiimageview * ImageView = [[Uiimageview alloc] initwithimage:image];
Imageview.frame = Self.view.frame;
[Self.view Addsubview:imageview];
}
-(void) Contentmode {
NSString * Path = [[NSBundle mainbundle] pathforresource:@ "Baby" oftype:@ "jpg"];
UIImage * Image1 = [UIImage Imagewithcontentsoffile:path];
Uiimageview * ImageView = [[Uiimageview alloc] initwithimage:image1];
Imageview.backgroundcolor = [Uicolor Graycolor];
Imageview.frame = CGRectMake (20, 20, 100, 100);
/*
Contentmode Property
This property is used to set the display of the image, such as centering, right, whether zooming, etc., there are several constants to set:
Uiviewcontentmodescaletofill
Uiviewcontentmodescaleaspectfit
Uiviewcontentmodescaleaspectfill
Uiviewcontentmoderedraw
Uiviewcontentmodecenter
Uiviewcontentmodetop
Uiviewcontentmodebottom
Uiviewcontentmodeleft
Uiviewcontentmoderight
Uiviewcontentmodetopleft
Uiviewcontentmodetopright
Uiviewcontentmodebottomleft
Uiviewcontentmodebottomright
Note that the above several constants, usually without scale, when the picture size exceeds imageview size, only part of the display in the ImageView. The Uiviewcontentmodescaletofill property causes the picture to deform and fills the picture with frame (default).
Uiviewcontentmodescaleaspectfit will ensure that the picture scale is the same, and that it all appears in ImageView, which means that ImageView will be partially blank. Uiviewcontentmodescaleaspectfill will also be the same as the picture, but it is filled with the entire imageview, it is possible that only some of the pictures are displayed.
*/
Imageview.contentmode = Uiviewcontentmodeleft;
Based on content other than the bounds cut
Imageview.clipstobounds = YES;
[Self.view Addsubview:imageview];
}
@end
/*******************************************************/
iOS Learning-uiimageview