This article reprinted to http://www.cnblogs.com/chivas/archive/2012/05/21/2512324.html
Uiimageview: You can assign a picture to Uiimageview by uiimage loading, you can specify the location and size of the display after loading.
1. Initialization
Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0.0,45.0,300,300)];
Imageview.image = [UIImage imagenamed:@ "a.png"];//load into picture
[Self.view Addsubview:image];
[ImageView release];
The Imagenamed method is not able to load a picture through a path, which can cause a memory warning to cause an automatic exit problem.
It is best to solve this problem by directly reading the file path [UIImage imagewithcontentsoffile] .
Nsimage *image = [[Nsimage alloc]initwithcontentsofurl: (Nsurl *)];
Nsimage *image = [[Nsimage alloc]initwithcontentsoffile: (NSString *)];
Such as:
1, ""
UIImage *image = [[UIImage alloc] initwithdata:[nsdata datawithcontentsofurl:[nsurl urlwithstring:@ "/http/ Farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg "]];
Uiimageview *imageview = [[Uiimageview alloc] initwithimage:image];
2, ""
Nsstring *path = [[NSBundle mainbundle]pathforresource:@ "icon" oftype:@ "PNG"];
Nsimage *myimage = [UIImage Imagewithcontentsoffile:path];
let a uiimageview respond to a click event
Uiimageview *imgview =[[uiimageview alloc] Initwithframe:cgrectmake (0, 0,320, 44)];
Imgview.userinteractionenabled=yes;
UITapGestureRecognizer *singletap =[[uitapgesturerecognizeralloc]initwithtarget:selfaction: @selector ( Onclickimage)];
[Imgview Addgesturerecognizer:singletap];
[Singletap release];
-(void) onclickimage{
Here, does whatever you wantto do
NSLog (@ "ImageView is clicked!");
}
Use Uiimageview to show pictures from the web