tags:

views:

113

answers:

1

hi all in my iphone application images are comming from xml feed and they have variant size,how can i resize them to fix width and hight programmatically.

my code is in which i want to display images in cell of same width and size.my image are comming from rss fedd.

int blogEntryIndex1 = [indexPath indexAtPosition: [indexPath length] -1];

imgstring=[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: @"image"];
NSURL *url = [NSURL URLWithString:imgstring];


NSData *data = [NSData dataWithContentsOfURL:url];

UIImage *img = [[UIImage alloc] initWithData:data];
cell.imageView.image=img;

please help me out if you can thanks in advance.

A: 

Hi change your code like this,

 NSString *imgstring =[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey:     @"image"]; 

 NSURL *url = [NSURL URLWithString:imgstring];

 NSData *data = [NSData dataWithContentsOfURL:url];

 UIImage *img = [[UIImage alloc] initWithData:data];

 UIImageView *subview = [[UIImageView alloc] initWithFrame:CGRectMake(10.0f, 10.0f,60.0f, 60.0f)];

 [subview setImage:[UIImage imageNamed:img]]; 

 [subview setContentMode:UIViewContentModeScaleToFill];

 [cell.contentView addSubView:subview];

try this one. I hope it will help you.

Sivanathan
Thanks nathan for replybut my image is are comming from rss feed in xmlso i need a code for all images
Nauman.Khattak
currently my code is NSString *imgstring =[[blogEntries objectAtIndex: blogEntryIndex1] objectForKey: @"image"];//then i extract image from url NSURL *url = [NSURL URLWithString:imgstring]; NSData *data = [NSData dataWithContentsOfURL:url]; UIImage *img = [[UIImage alloc] initWithData:data];//now em gona display it in cellcell.imageView.image=img;
Nauman.Khattak
Hi thanks for editing code but its still not working and i am reciving 4 warning my application crash and give me follwoing error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIImage length]: unrecognized selector sent to instance 0x3b36f50'
Nauman.Khattak