UISearchController search result cell background color - ios

My UISearchController displays search results in UITableViewCells with background colour that I have not set
I can see by debugging the views that this grey colour is that of the cell.contentView. However, it doesn't react to me setting
cell.contentView.backgroundColor = [UIColor whiteColor];
in tableView:cellForRowAtIndexPath: method.
Are there any other methods to override that strange grey colour?

Are you able to provide an example project that reproduces your scenario? What does the tableView:cellForRowAtIndexPath: look like? If so, we can probably be much more helpful in determining the issue.
Without knowing specifics, it might be worth trying to set the contentView's backgroundColor in tableView:willDisplayCell:forRowAtIndexPath:, which occurs a bit later than tableView:cellForRowAtIndexPath:
It may also be worth making your own subclass of UITableViewCell so that you can better control the coloring of the cell.

Related

How do I make a UITableViewCell separator show up?

I'm having a similar problem to this question: UITableViewCell separator not showing up.
However, the proposed solutions don't work for me. Specifically, I've checked the following:
My UITableViewCell subclass does not override drawRect:.
I don't have a custom UITableView and, therefore, I'm not overriding layoutSubviews.
In Interface Builder, I have the Separator attribute of the Table View set to "Single Line".
I've tried programmatically setting tableView.separatorStyle to UITableViewCellSeparatorStyleSingleLine.
But still the separator line will now show up… Does anyone know of something else that could cause this behavior or have any ideas for how I might track down what is hiding/removing the separator line?
EDIT:
Well I feel silly… In trying to create the screenshot requested by valheru, I noticed that the lines ARE there, but are almost exactly the same color as the background, so I couldn't see them until the screenshot was blown up. I had suspected earlier that the separator color might be the issue, and I tried testing for that by setting the separator color to white (my background is almost black), but it turns out that there was some copy/pasted code that was programmatically resetting the color to the almost-invisible color.
Thanks valheru for leading me to the answer. :-)
Check the height of your table view's row and the height of the cell. Make sure that the row's height is not less than the cell's height.

How to prevent cell turnaround effect?

I'm sorry about I can't upload images because of my low reputation point.
(Screenshots)
http://twitter.com/hseongeon/status/410214108881907712/photo/1
http://twitter.com/hseongeon/status/410214156785029120/photo/1
In most iOS development cases, turnaround effect appears on cells by selecting themselves.
As you can see in my screenshots, however, sometimes the effect make a view's background color and text color what I don't want to be. (like badgeView in my screenshots)
I'd like not to change my badgeView's color when cells are selected.
How to do this?
Thank you in advance.
Set the property selectionStyle on your cell to UITableViewCellSelectionStyleNone. This will prevent any calls to setSelected or setHighlighted on your cell.

Scroll the UICollectionView Background With The UICollectionView

I am building an app that is presenting articles from a blog. I am using UICollectionView to present images that are parsed from the blog for each of the cells. This is my first go-round with a UICollectionView so I am wondering how you set up a background image of something like shelves that will scroll with the UICollectionView?
I have tried using:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
But this doesn't do anything.
What you're trying:
self.collectionView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"shelves.jpg"]];
should work. I do exactly this in viewDidLoad and it works for me. I would check that you're getting a valid image. Perhaps "shelves.jpg" needs to be added to the project?
You can just set the size of a UIImageView for your background to a size that is larger than the current UIView size then change the origin (increment) of that UIImageView based on your current visible cells for your UICollectionView. This would give you a side scrolling (parallax) effect based on which cells are currently being viewed.
There are other parallax effects people have created that you can get creative with to apply to your scenario. The idea is pretty simple.

Opaque UILabel in a UICollectionViewCell has strange rendering behavior

I've experienced some really weird behavior with UILabels in a UICollectionViewCell today and I'm hoping one of you guys can shed a light on this.
I can't show you code or full screenshots, but I will try to explain and illustrate it as well as possible;
I have a UICollectionView that has several cells and supports horizontal scrolling.
In the cells I have a label that I set on
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath and clear on - (void)prepareForReuse.
Seems pretty normal, and I even have an implementation exactly like this that works without any weirdness.
Now, for performance reasons, I set the UILabel's opaqueness ON in Interface Builder.
When I scroll around a couple of times, I get to see this:
Whenever I turned opaque OFF in Interface Builder, I get to see this:
I have a lot of experience with UITableViews and UICollectionViews (and reusing, etc) but there is no way I can explain this behavior properly...
yourLabel.backgroundColor = UIColor.whiteColor()
UILabel's default background color is clear color. If you set the label to opaque, you also need to set the background color to an opaque color.

UITableView row count like iOS Mail app

How do you add counts inside of a UITableView UITableViewCell like the iOS Mail app?
In addition to DDBadgeViewCell (mentioned by #micpringle), there's also TDBadgedCell.
I tried out both and found TDBadgedCell to suit my needs more, as it puts the badges over the cell's text rather than under it, meaning the badges are visible even for cells with long texts.
The project also seems to be (currently, at least) more active than DDBadgeViewCell. (That being said, there seems to be a bug in the non-ARC version of TDBadgedCell.)
Create a custom UITableViewCell, position the labels where you want them (title, subtitle, count, whatever you need). I highly recommend Matt Gallaghers custom UITableView code - it takes a lot of the headaches out of dealing with custom rows. You'll have to follow Matt Gallaghers steps for customizing the cell.
To get the appearance of the count label as close as possible to your example (mail.app), you'll have to set the UILabel backgroundColor to gray (or whatever color you want it to be), textColor to white, and layer.cornerRadius to something equal to half the height of the label (if label is 20 high, cornerRadius should be 10). This will result in a UILabel with white text, gray background, round corners. Note - this isn't the most efficient method of doing this, but Apple hasn't put up the WWDC session video where they explain the performant method better (I missed that session).
The easiest solution would be to set an UILabel as accessoryView or using a custom UITableViewCell subclass which could be designed using IB.
I'd recommend creating a simple rounded UIView and a UILabel as a subview in it. I'd probably create a UITableViewCell subclass to manage the content.
Definitively the most easy way would be using a ready-to-use class like TDBadgedCell

Resources