Shadow not showing for UITableVIewCell contains UIImageView - ios

I am playing around with my first iOS app.
I set up a cell shadow like this:
ucell.layer.shadowOffset = CGSizeMake(0, 1);
ucell.layer.shadowColor = [[UIColor blackColor] CGColor];
ucell.layer.shadowRadius = 1;
ucell.layer.shadowOpacity = .15;
Later I add a UIImage view as the background:
ucell.backgroundView = [[UIImageView alloc] initWithImage:tempImg];
Then the shadow of this cell disappears.
Also in the other cells where I have a image view on the left side, the shadow is not showing at the bottom of the image part:
1 http://imageshack.com/a/img538/6425/01mv70.png
how can I fix this problem.
Thanks in advance!

I guess you have added that imageview sticking to the cell's top and bottom. Thats why it is not showing. If you have added that imageview one pixel above the actual cell contentview, it will be shown.

Related

iOS 7 custom separator does not mimic default separator behavior.

I am trying to draw a custom separator in my custom UITableViewCell.
CALayer *border = [CALayer layer];
border.frame = CGRectMake(0, 60, 320, 1.0f);
border.backgroundColor = [UIColor blackColor].CGColor;
[self.layer addSublayer:border];
My custom UITableViewCell height is 60.
For some reason, when I scroll to the bottom of my table view, all the separators appears normally, but as I scroll back up the table, the table cells at the top do not show my separator.
I can potentially set my separator with y of 59:
CALayer *border = [CALayer layer];
border.frame = CGRectMake(0, 59, 320, 1.0f);
border.backgroundColor = [UIColor blackColor].CGColor;
[self.layer addSublayer:border];
But this behavior is not desired because when I select a row, I want the separator on the previous cell to disappear, this only happens when y is 60, which is the height of my cell.
If your cell height is 60pts, then setting the y position of a UIView to 60pts and 1pt heigh is going to draw it outside of the bounds of the cell.
This might work initially because of the order the cells are added to the tableView.. I.e The top cell is added after the second cell down so the 1pt separator as been drawn on top of the second cell... However when you scroll back up, the cells are added back to the tableView in a different order causing the separator to be hidden as the cell below it is drawn on top.
To get around this, you have to draw the separator inside the bounds of the cell.
I don't really understand why you want the separator on the previous cell (i presume you mean the last selected cell) to disappear but could you achieve this by overriding setHighlighted:animated: and setSelected:animated: on a custom UITableViewCell subclass?

UICollectionViewCell pixel artifacts

I have a custom UICollectionViewCell, I have few views in its contentView.
I have an UIImageView with image (1 pixel colored) and I use it to fill my view.
I also cut the corners like this -
self.myBackground.layer.cornerRadius = 8.0;
self.myBackground.layer.masksToBounds = YES;
Color of my view and all collectionViewCells and their contentViews is [UIColor whiteColor]
But I am getting weird grey line below it. I am not setting it anywhere and I don't need it.
How can I remove it?
I have found the answer, it is separator. After setting separator view to nil it disappeared.

cell.selectedBackgroundView covering up UIViews in a cell

I have a table. Within each cell of a table, I created a simple bar graph (which is just 2 UIViews with background filled).
I have set cell.selectedBackgroundView to an image.
When the cell is selected, it seems to cover up parts of the bar graph. Does anyone know why?
The red is the selected cell. The top and bottom are unselected cells:
In the image, the grey bar, the brown bar, the 2 numbers (x.xx) and the semi-transparent line at the left, are all subviews of 1 UIView. The UIView is added to the cell. The line and the 2 numbers are still there, but the 2 bars are gone.
Here's some code:
Cell selected image set like this:
UIImage *selectedRowImage = [UIImage imageNamed:#"table-selectedcellbg-red-45px-stretch.png"];
cell.selectedBackgroundView = [[UIImageView alloc]initWithImage:[selectedRowImage resizableImageWithCapInsets:UIEdgeInsetsMake(selectedRowImage.size.height, selectedRowImage.size.width/2, selectedRowImage.size.height, selectedRowImage.size.width/2)]];
[cell sendSubviewToBack:cell.selectedBackgroundView]; // This didn't make a difference
Adding the view set like this:
UIView *graph = [barGraph getGraph];
UIView *graphView = [[UIView alloc]initWithFrame:CGRectMake(150, (tableView.rowHeight - graph.frame.size.height)/2, graph.frame.size.width, graph.frame.size.height)];
[graphView addSubview:graph];
[cell addSubview:graphView];
Any ideas?
I think the answer can be found in the UITableViewClass Reference:
selectedBackgroundView
...
Discussion
The default is nil for cells in plain-style tables
(UITableViewStylePlain) and non-nil for section-group tables
(UITableViewStyleGrouped). UITableViewCell adds the value of this
property as a subview only when the cell is selected. It adds the
selected background view as a subview directly above the background
view (backgroundView) if it is not nil, or behind all other views.
Calling setSelected:animated: causes the selected background view to
animate in and out with an alpha fade.
It seems as if selectedBackgroundView only works well if the corresponding backgroundView property of the cell is not nil.
Try adding a backgroundView and test again.
Hope that helps you out.
Edit:
Since this wasn't the solution, I tried to reproduce your problem, but with no success: the backgroundView stayed behind the QuestionMarkIcon (a view like your graphView)..
Code:
- (UITableViewCell*) tableView: (UITableView*) tableView cellForRowAtIndexPath: (NSIndexPath*) indexPath {
//...
UIImage* selectedRowImage = [UIImage imageNamed: #"strecheableImage.png"];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage: [selectedRowImage resizableImageWithCapInsets: UIEdgeInsetsMake(selectedRowImage.size.height, selectedRowImage.size.width/2, selectedRowImage.size.height, selectedRowImage.size.width/2)]];
UIView* graph = [[QuestionMarkIcon alloc] init];
UIView* graphView = [[UIView alloc]initWithFrame: CGRectMake(150, (tableView.rowHeight - graph.frame.size.height)/2, graph.frame.size.width, graph.frame.size.height)];
[graphView addSubview: graph];
[cell addSubview: graphView];
// ...
}
This is how my stretchableImage.png looks like:
Cell 1 is selected but the QuestionMarkIcon (your graph) stays in front:
Sorry I couldn't help.

iOS - UITableViewCell being clipped

I have a UITableView with a tiled background image
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg.png"]];
With this image pattern I have noticed that on every 3rd table cell the pattern does not match and a line is clearly seen on the background image. At exactly the same position the bottom of my UITableViewCell is being clipped so I am losing the bottom of my cell. I am assuming that both these problems are linked.
I was wondering if someone could explain what is happening here and perhaps offer a suggestion to fix my table cell from being clipped.
The image on the right is the clipped cell and the image on the left is the normal cell
I sorted this. I was changing the UITableViewCell frame origin value to create a gap between table cells that was causing this problem.
self.contentView.frame.origin.y = 20;
Instead of this I just adjusted the bounds to create the gap between cell rows.
CGRect bounds = self.contentView.bounds;
bounds.size.height = bounds.size.height -20;
self.contentView.bounds = bounds;
Hope tis helps someone in the future

how to have a double border for a cell

I want to display a double bordered like following image...
The border has a dark color (magenta) and a light color (white) (not the actual colors).
I have created a custom .xib file and a custom class extending UITableViewCell for my table view cells.
self.tableView.separatorColor = [UIColor whiteColor];
Then in the custom table view class, I did this...
- (void)awakeFromNib
{
[super awakeFromNib];
UIView *cellBottom = [[UIView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height, self.bounds.size.width, 1.0f)];
cellBottom.backgroundColor = [UIColor magentaColor]; //
[self addSubview:cellBottomView];
// ... other code
}
I got the following result... there seems to be some gap between backgroundColor and separatorColor.
Why is this happening? The height of UIView has been set to 1 and is positioned at the bottom of UIView as well.
If there is some better solution to this could somebody throw some light on that?
Michal Zygar is partially correct.
Make sure your -(NSInteger)tableView:(UITableView*) heightForRowAtIndexPath:(NSIndexPath*) is correctly set to the height of the view. It doesn't automatically do that for you.
The other tip I would suggest as I do it myself, is to NOT use separators. Set your separator to none, and then add in two 1px-heigh views at the top and bottom of the cell in the XIB file.
Make sure to set the autosizing for the bottom two to stick only to the bottom edge, just in case you want to change the cell's height!

Resources