UIImage inside table view cell - iphone

Inside my table view for each cell I have an image along with some text and other stuff. When I select a cell I want the image also to be covered with blue overlay. Right now all other stuff excluding image is getting selected and a blue overlay covers the cell.
How to achieve this?

You won't be able to have that blue overlay to cover your image. The blue gradient is the backgroundView of the cell, whereas your UIImage is either drawn inside the contentView or added to it as a subview.
A possible workaround would be to add a CALayer on top of the whole cell that would mimic the default blue background.

It seems like there should be a way to do this without modifying your image, but all I can find so far is to specify a new image when the cell is selected. UIImageView has a property for both image and highlightedImage, so it would seem you need to provide your own image to use when the cell is selected, so you would need to set cell.imageView.image and cell.imageView.highlightedImage.
Sam's workaround would be a good approach, also. Especially if you don't want to provide your own image

Related

set margin to collection view's cell

I'm beginner with collection view,
I need to create cell like this
Can I do it from Storyboard?
I want to add margin of cell = 4 or 5 in the top, bottom, lift and right in iPhones and iPads of all sizes, or I if need to do that programmatically How I can add the contents of the cell like the image above?
There is no "margin" here. There is simply a rectangle with a shadow, and everything else is drawn in front of it. The simplest solution is probably a custom UIView that draws itself as a rectangle with a shadow. Make that the content view's direct subview, and everything else in the cell is a subview of that. The inset of the rectangle-with-shadow within the cell's content view can be determined by autolayout (and the position of all the stuff inside it can be determined by autolayout too).
Thus it was trivial for me to obtain this sort of thing:
And of course you can tweak the border color, the background color, and so forth.

UITableCell Centered with Shadow

I would like to build my UITableView in similar way to Google+ app, which has:
UITableCell width of about 310 I guess but the important thing is they centered, I dont know how to achieve that...
There is a 1-2 pixels of shadow beneath the cell.
Please help me to understand how to position my cells the same way and how to add the shadow effect.
Thanks.
UITableCell width of about 310 I guess but the important thing is they centered, I dont know how to achieve that... : You'll have to create a own subclass of UITableViewCell. Here you can position the controls which you need however you need. You can achieve the above shown UITableView only by creating your custom UITableViewCell. You can refer this
There is a 1-2 pixels of shadow beneath the cell. : This can be possible only by using the image with shadow as a background of your customized UITableViewCell.
OK so I finally got the solution.
I used a background image for each cell that takes the whole width (I kind of cheated) and incorporate the shadow and the 10px separation in the background image.
Of course I had to use Photoshop or similar program to achieve that. so the UITableView and the Cell width should be 320, and the height of the cell should contain the shadow and the separation as well.
This is how I make the table to look exactly like I want it to be!!

BackgroundView does not adapt round corner in Grouped UITableView

I am learning how to use storyboard and i am trying to build a UITableViewCell with grouped style. I tried to put a png file and set it as background for the cell.
My png file is a rectangular image.
When i open it in simulator, I found the first cell corner become a rectangle rather than a round corner cell.
What should i can in order to make the first and last cell to be corner rounded?
This is a know problem when using Grouped TableView.
You can either use the backgroundColor of UITableViewCell or you will have to draw the background by hand and check wether is the first of last in the section and add the rounded corners.
have a look at this post
Try to set the property clippingSubviews of your cells to YES.

Covering space from one UITableView's cell with another one

The design of the UITableView is something like this:
I want to make my cells with a tiny triangle, like in a comic book. The thing is, how can i add the triangle to the size of my custom cell? The common rectangle size wouldn't work if i want the user to be able to tap that little rectangle.
And how can i make the opposite? I want the triangle to cover the space of another cell, so tapping the little triangle of the first cell, covering part of the second cell's rectangle space, would activate de first one. This is, substracting a little triangle from the cell's space.
Not sure it would work, but building on user697562's comment, you could try the following:
Add a small UIView to the table cell to represent the small triangle
Rotate it using its transform property, making sure that, along with its frame, it will have the proper placement.
Add a UITapGestureRecognizer to the UIView
Add an instance variable to the view to save the indexPath of the cell it's in (or even the above cell, since it will be associated with the above cell). This way when the gesture recognizer is triggered, you know what row you're in.
Write the action method associated with the gesture recognizer to do the same thing as tableView:didSelectRowAtIndexPath: would do for the above cell.
Set the separatorStyle property of the UITableView to UISeparatorStyleNone, so that it won't draw the lines between cells. If this doesn't work just set the separatorColor property to your table cell's background color.
Draw a border along the top & bottom of the cell, accounting for the triangle.
Good luck with it! Let me know whether it works if you try it.

How to put gradient style table cell in a table?

Hey, I am making a custom table cell right now but my custom cell is just white cell with some buttons and labels in background color which looks not that great.
Is there a way to render the background color so that the cell has some vertical gradient effect?
For example, on top of the cell it looks white and as it gets closer to center of the cell, it gets darker.
But as it gets closer to the bottom of the cell, it gets whiter again.
A great example would be this free app called "friendsaroundme".
Another thing is that I don't want to use custom image to do it (i.e make the cell.backgroundcolor = [uicolor colorwithpatternimage:somethingsomething.png..... ) because it's not that flexible.
So is there anyway to render the gradient style programatically?
You can use a CAGradientLayer as the background layer. Remember a table view cell is just a UIView. You can add a new layer to the layer tree with:
[[[self view] layer] addSublayer:gradientLayer];
I wrote a blog post on how to do this with UIButtons. The same technique applies.