Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a UIImage to UIImageView programmatically

In .h file I declare this;

IBOutlet UIImageView *image;

In .m file;

UIImage *image1 = [UIImage imageName:@"http://image.com/image.jpg"];
image = [[UIImageView alloc] initWithImage:image1];
image.frame = CGRectMake(0,0, 50,50);
[self.view addSubView:image];

and I connected the UIImageView from the Interface builder. But I need to do this Only by code (without using the Interface Builder). Can someone help me modify the code so that I could do this only by code?

like image 346
Illep Avatar asked Jun 30 '26 03:06

Illep


1 Answers

I THINK you have some problem in displaying a remote image in uiimageview so i thing u should do that fashion.

NSData *receivedData = [[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://image.com/image.jpg"]] retain];
UIImage *image = [[UIImage alloc] initWithData:receivedData] ;

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0,0, 50,50);
[self.view addSubView:image];

[image release];
[imageView release];
like image 191
Rohit Dhawan Avatar answered Jul 01 '26 17:07

Rohit Dhawan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!