I have a custom UITableViewCell which fills the cell with a background PNG and a label.
When the user selected the cell, I wish to have the back ground change for an instant to visually give them indication that the row was selected. Similar to the default behavior when a custom cell is not used.
How is that done?
You can try this tutorial:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
Posting as answer so this is correct (originally from BahaiResearch.com):
In this scenario the correct answer is to use the following, when setting the image originally:
image.HighlightedImage = [UIImage ..];
Otherwise you are loading images when the highlight event occurs and in theory there's a slight delay, etc.
let me clear first do you wish to change the backgroundimage.png??
if yes and you are using UIImageView for that then you can write following code in rowDidSelected event..
UIImageView *myImageView = [Cell viewWithTag:1]; //Tag is given in Interface Builder for the ImageView
myImageView.image = [[UIImage alloc] imageNamed:#"newimage.png"];
Related
see below figure, it has- TableView & tablecell have same background image i.e.tableview & tablecell must not look different. in tableCell there must be one button .
To achieve this you'll have to create a customized UITableViewCell.
You'll required 4 background image for your cell.
a. Image Facing right. b. Rollover image facing right. c.
Image Facing left. d. Rollover image facing left.
You'll have to set alternate image to your cell. And when you click on the cell you'll need to change the background image of that particular cell to Rollover image.
Also you'll have to manage the frames of your rest of the control accordingly.
This is nothing but the image. You have to set an image in every tableviewcell by passing the condition
if(indexpath.row/2 == 0)
<set_image1>
else
<set_image2>
then adjust other parameters according to your desired frame position.
Note: You need to use dynamic tableviewcell height &
You need for images for this.Two when cell is not selected & rest two when cell got selected
Enjoy Programming!
I did this following way:
I created two prototype cells having different Cell identifier
e.g. left cell identifier= Cell1 & right cell identifier=Cell2.
simply put one round-rect button, make it as custom because it shows only in image shape
made table cell background color as clearColor, it requires because for the feel of table cell & tableview must look same.
also set tableView background color as clearColor & add images to both button.
if ((indexPath.row)%2!=0)
{
CellIdentifier=#"Cell1";
}
else
{
CellIdentifier=#"Cell2";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *topicButton=(UIButton *)[cell viewWithTag:1];
NSString *topicNameLabel=[_topics objectAtIndex:indexPath.row];
I'm writing a small application to teach myself new design and information retrieval tricks. I'm using the following line to set the background of my UITableViewCell subclass:
cell.contentView.backgroundColor = [UIColor blackColor];
... but it doesn't seem to want to get behind that accessory view:
How do I get the backgroundColor to actually span the entire background of the UITableViewCell?
The accessory view is not added to the cell's contentView. As you can see, the content view is resized by shrinking from the right so the accessory can fit in. This also happens when the delete button is shown.
You need to set the backgroundColor of the whole cell - furthermore, this has to be done in the tableView:willDisplayCell:forRowAtIndexPath:
delegate method.
If you want to set color of entire cell, then use -
cell.backgroundColor = [UIColor blackColor];
Not exactly a definitive answer to this question, but it works well when you use the "grouped" view instead of the standard UITableView style.
I have a tableView and you can add cells. and it doesnt show my image on the left hand side of the newly added cells. I'm using the default cell style and here is my code:
This is the button that allows us to add a cell.
- (IBAction)outlet1:(id)sender {
[cart.cells addObject:#"1"];
cart.cell.imageView.image = [UIImage imageNamed:#"paddle1.png"];
}
Please help! I checked the name of the image and it seems good. Thanks!
It would be better to place the image to the UITableViewCell inside the cellForRowAtIndexPath method, by setting the image to cell.imageView.image
i have a my requirement disable the table cell.i have controls on that cell like(textFeild,imageview,button).when i access one control it prefprms another action so plz help me . thanks in advance.
It is not clear what you want exactly. If you just want to disable the cell i think you mean this
cell.userInteractionEnabled = NO;
But what do you mean by when i access one control it performs another action ?
I would suggest using custom UITableViewCells. Put all your controls on custom cells, that way all the events pertaining to that controls would be called in the actions in your custom cell class. In the tableView class you just don't have to give any implementation for didSelectRowAtIndexPath. That way your controls on the cells would be clickable.
It could also apply a color effect:
UIView *lab = [[UIView alloc] initWithFrame:cell.frame];
[lab setBackgroundColor:[UIColor lightGrayColor]];
cell.backgroundView = lab;
I'm trying to place a UIImageView in a UITableViewCell.
I create a special view called ProductView. In that view, I have several components, one of them being a UIImageView. I set this ProductView as content view of the UITableViewCell. Everything is drawn properly except the UIImageView. UIImageView gets scaled meaninglessly. It's height gets twice the height of the table cell size.
I've spent hours trying to solve this problem. I've set the frame of UIImageView manually, I've called drawRect method of UIImage in UIImageView, neither of them worked.
I'm thinking of replacing UITableView with a UIScrollView if I can't find a solution. Does anyone know how to solve this problem?
Use the Custom cells, and place all the UI component inside that cell, (including the UIImageView), and in cellForRowAtIndexPath method, set the image like following:
[cell.imgView setContentMode:UIViewContentModeScaleAspectFit];
[cell.imgView setFrame:CGRectMake(cell.imgView.frame.origin.x, cell.imgView.frame.origin.y, 120, 79)];
[cell.imgView setImage:[UIImage imageNamed:#"image.png"]];
And if you need to know how to use custom cells, follow this tutorial :
iPhone Programming Tutorial: Part 6: Creating custom UITableViewCell Using Interface Builder [UITableView]
Hope this helps you...
I've had the same problem and realized in the end that the issue wasn't anything to do with automatic resizing, it was simply that I was not getting the UIImageView, but its parent view (the table cell), due to clashing tag values (I was getting the view through callUIImageView *pictureView = (UIImageView *)[cell viewWithTag:0]; and tag zero was also set on the cell). Fixed by just changing the tag value.