I have a tableView based app and I made a custom TableViewCell that have a thumbnail in it.
I wish to programmatically choose a default thumbnail image for my custom TableViewCell.
any ideas on how to do that?
Thanks.
Set tag for your UIImageView in your custom UITableViewCell, for example, let it be 10.
When you want to show image in that view for some UITableViewCell *cell; do next:
UIImageView *imageView = (UIImageView *)[cell viewForTag:10];
imageView.image = [UIImage ....];
- (void)setCellIconImage:(UIImage*)iconImage
{
self.imgView.image = iconImage;
}
Related
How do you make the whole UITableViewCell a custom image? I do it for prototyping purposes and I can't find where to start. I basically need 3 UITableViewCells with the same image - so they all are reusable cells.
Any ideas on how to do this? Thanks.
I think what you want is : backgroundView property of UITableViewCell
You can do it like this :
-(void) tableView:(UITableView*)tableView
willDisplayCell:(UITableViewCell*)cell
forRowAtIndexPath:(NSIndexPath*)indexPath;
{
static UIImage* bgImage = nil;
if (bgImage == nil) {
bgImage = [[UIImage imageNamed:#"myimage.png"] retain];
}
cell.backgroundView = [[[UIImageView alloc] initWithImage:bgImage] autorelease];
}
Or Simply Use :
((UIImageView*)cell.backgroundView).image = [UIImage imageNamed:#"customBackground"];
((UIImageView*)cell.selectedBackgroundView).image = [UIImage imageNamed:#"selectedBackground"];
If u are planning to change a lot of things in the cells I will go this way:
You can create a custom cell class and design it with the a full cell image background. Then you will create cells of that cell class in the cellForRowAtIndexPath method.
If you just need to add and image as background and you dont need anything else then just create an imageview with the proper size and add it as a subview of the cellview
To achieve this you'll have to create a customized UITableViewCell. You can create a cell and assign background image to it.
This background image will be used for all the cells.
You can use cell's backgrounView to add an Image or you can use cell's contentView and add the subViews to the cell Starting with an Image look at THIS thread you will get an idea
UITableViewCell Refrence
I'm trying to build a menu using a UItableView with Custom cells which have an image and some additional text. However, when I try to load the image using the code below I get a SIGABRT error, why?
imageTmp = [UIImage imageNamed: #"HR1.jpg"];
cell.image = [UIImageView setImage:imageTmp];
The UIImageView is called image
shouldn't it be
cell.imageView.image = imageTmp;
I need to display one or more different images from array in one cell of UITableView like grid view without using any API for example three20 etc . Please give solution for my question.
This will put an image at the beginning of the cell:
[cell.imageView setImage:[UIImage imageNamed:#"whatever.png"]];
This image you can place anywhere on the cell by altering the frame:
UIImage *accessoryImage = [UIImage imageNamed:#"whatever.png"];
UIImageView *accImageView = [[UIImageView alloc] initWithImage:accessoryImage];
accImageView.userInteractionEnabled = YES;
[accImageView setFrame:CGRectMake(self.tableView.frame.size.width-70, 5, 28.0, 28.0)];
[cell.contentView addSubview:accImageView];
I have a UIImageView that I have already set an image to. This works fine, but later, I want to change that image. So, I set a new image for the image property, but when I view the app, that image is set as a second image over the first:
UIImageView *image;
image = (UIImageView *)[cell viewWithTag:0];
image.image = [UIImage imageNamed:#"History_Row2.png"];
How can I replace the current image in my UIImageView rather than seeming to add another?!
I did it by retaining the UIImageView, and keeping a reference as an ivar, releasing on dealloc.
image = (UIImageView *)[cell viewWithTag:0];
That was returning a UITableViewCell rather than a UIImageView, this is because the tag 0 is the default and it needs to be changed to a different number. After doing this it worked.
i have the different image with the different size too, i want to put it in cell.imageView.image in every cell, but i want make same size in every cell although the image have the different size, i write this on my code :
UIImage *image = [UIImage imageNamed:imageName];
cell.imageView.image = image;
cell.imageView.layer.masksToBounds = YES;
cell.imageView.layer.cornerRadius = 5.0;
float sw=image.size.width/cell.imageView.image.size.width;
float sh=image.size.height/cell.imageView.image.size.height;
cell.imageView.transform=CGAffineTransformMakeScale(sw, sh);
but it doesn't work, i'am sure that's right..
any body can help me.??
I just ran into this same problem. I wanted the photos to be 65 x 65, but they were filling in the size of the UITableViewCell instead. I resolved it by creating the UIImageView programmatically and adding it as a subview to the UITableViewCell. For example:
UIImageView *imageView = [[UIImageView alloc] initWithImage:photo];
imageView.frame = CGRectMake(6.5, 6.5, 65., 65.);
[cell addSubview:imageView];
Edit for clarity: This problem was occurring when I tried to create the UIImageView in Interface Builder. I took it out of Interface Builder and added it programmatically instead.
In case anybody else runs into this with custom cells: it appears that if your custom cell has an outlet named imageView, it will be treated like the image view in a basic-style cell, i.e. the image view's size will be adjusted. Simply picking another name avoids this behavior.
If your cell is a built in cell, it is supposed that the cell will resize all the images to a fixed, default size. Can you post an screenshot of your application as well?
I just saw your question. I faced the same problem, and the code worked for me is following:
cell.imageView.frame = CGRectMake(0, 0, 50, 50);
Hope, it will solve your problem