UIImageView From Url in iPhone


In this article I will create an Empty View application. Here I will implement an Image View using code to upload an image. We use a NSData defined in the NSObject base class.

To understand it we use the following..

Step 1

Open XCode by double-clicking on it.

Step 2

Create a New XCode Project by clicking on it.

Step 3

Now Select Empty View Application and click on Next.

Step 4

Now provide your Product Name and Company Identifier.

Step 5

Select the location where you want to save your project and click on Create.

Step 6

Now here we write the code.


#import <UIKit/UIKit.h>
@interface testviewAppDelegate : UIResponder <UIApplicationDelegate>
@property (strongnonatomicUIWindow *window;


#import "testviewAppDelegate.h"
@implementation testviewAppDelegate
- (void)dealloc
[_window release];
[super dealloc];
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
self.window = [[[UIWindow allocinitWithFrame:[[UIScreen mainScreenbounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
CGRect myimagerect = CGRectMake(00320480);
UIImageView *myimage = [[UIImageView alloc]initWithFrame:myimagerect];
NSURL *url = [NSURL URLWithString: @"http://dblog.com.au/wp-content/elephant.jpg"];
NSData *data = [NSData dataWithContentsOfURL: url];
myimage.image=[UIImage imageWithData: data];
myimage.opaque = YES;
[self.window addSubview:myimage];
[myimage release];
[self.window makeKeyAndVisible];
return YES;

Step 7

Finally we click on the run button to show the output.

Step 8

Output  in iPhone:


Similar Articles