What is the difference between a highlighted UITableViewCell and a selected UITableViewCell? - iphone

A UITableViewCell reflects two distinct states: Highlighted and Selected.
For me, they sound identical so what exactly are the differences?

Highlight happens on touch down.
Selected happens on touch up, followed by the call to didSelectRowAtIndexPath:. In a standard UITableView, there is usually a small delay between the highlight and the select.

From appearance point of view:
Selected Cell:
The selection affects the appearance of labels, image, and background. When the selected state of a cell is set to YES, it draws the background for selected cells with its title in white.
The background will be drawn based on selectionStyle & selectedBackgroundView values. I could not really see any white titles as Apple documentation mentioned. I just see the background changes as expected.
Highlighted Cell:
The highlighting affects the appearance of labels, image, and background. When the highlighted state of a cell is set to YES, labels are drawn in their highlighted text color (default is white).
Note that for highlighting to work properly, you must fetch the cell’s labels using the textLabel and detailTextLabel properties and set each label’s highlightedTextColor property; for images, get the cell’s image using the imageView property and set the UIImageView object’s highlightedImage property.
Again I don't really that see that the default highlighted text color is white.
So I conclude that selected cell appearance affects the background of the cell while the highlighted cell affects the labels text colors as well as the image (if highlightedImage property is set)

Related

Making font colour negative to the background. iOS

I want to make text in a UILabel appear of a color negative to that background it is placed on.
I am placing the label on a web view, and I want that label to be always of a negative colour to the background so that no matter what colour (when web view is scrolled) is exactly below the text, it is always visible in a negative colour.
Thank you.
I don't recommend you to do that because the scrolling part of the webView won't be smooth with all those calculations in it. So I suggest you to set a background ImageView to your label and set a image with a negative color to your font color to that ImageView
An alternative would be setting the shadowColor to the opposite of the textColor (for example, white and black, respectively), ensuring that you'll always be able to pick out the text regardless of the web view's background color.
Don't forget to set the shadowOffset too!

UITableViewCell Background Color?

I have done a fair bit of googling on this and I can't find the right solution. I have a UITableView of which I want to change the colour of the background of the cells. I have found solutions to doing this but it only deals with cells which have content or data as it were.
I need to colour the background of those unused cells as well.
Try setting the background colour of the tableView itself. Those "empty cells" at the bottom aren't really cells at all - they're just separator lines drawn over the background.
Even though UITableViewCell inherits from UIView, changing the backgroundColor property of the cell itself won't do anything. You need to change the background color of the cell's contentView, such as
cell.contentView.backgroundColor = [UIColor greenColor];
This is because the subviews of a UITableViewCell are actually subviews of the cell's contentView, because the contentView knows how to resize its subviews if a cell is put into editing mode; the cell itself doesn't know how to do that.
I'm not sure what you mean by unused cells. If you tell your tableView there are 10 cells and you only provide content for 8 of them, you'll still have 10 green cells, if that's what you mean by "unused".

unused cells background color

I have a UITableView which displays about 5 cells at a time, yet in my table there might be cases where there are only 2 cells with content as seen on this picture:
alt text http://www.freeimagehosting.net/uploads/30d3602979.png
The white cells below do not look nice, how can I change the background color of these cells to black too? UITableView does not have a backgroundColor property.
Thanks!
A UITableView inherits from UIView, and UIView always has a backgroundColor.
You can also change the background color to "non-opaque", and then change the background color of your parent container.
tableView.backgroundColor = // some UIColor

Custom UITableViewCell always black unless set to anything but clear

My custom UITableViewCells always have a black background unless I set the background of the UITableView to clear.
However I want to set the background colour to another colour and as soon as I do the cells turn black (even though the background of the control does change)

Changing border color in iPhone UITableView cells (non-grouped)

I've read (and used) the code here which illustrates how to change the background color and border color of a UITableViewCell in grouped mode on the iPhone. I'm writing an app now which has a non-grouped UITableView and I need to change the border color of the cells. I know that I can modify the code and create a new background view and apply it, but is it necessary?
Is there an easy way to specify the border color of a UITableViewCell if it is a non-grouped style?
If by "border color" in a plain table view you mean the separator lines between the cells (default color gray), you can customize this color for the whole table view via:
tableView.separatorColor = [UIColor blueColor];
See the UITableView reference.