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
Related
I have subclassed UITableViewCell class to add shadow below my cell. The shadow is added correctly, when TableView appears on screen. But, when I scroll tableview down, and cell with shadow hides above the screen, the shadow disappears.
- (void)layoutSubviews {
[super layoutSubviews];
if (self.shouldAddShadow) {
self.layer.shadowOpacity = 0.5;
self.layer.shadowRadius = 1.5;
self.layer.shadowOffset = CGSizeMake(0, 3);
self.layer.shadowColor = [[[UIColor appDarkDividerColor] colorWithAlphaComponent:0.9] CGColor];
[self setClipsToBounds:NO];
[self.layer setMasksToBounds:NO];
CGRect shadowFrame = self.layer.bounds;
CGPathRef shadowPath = [UIBezierPath bezierPathWithRect:shadowFrame].CGPath;
self.layer.shadowPath = shadowPath;
}
}
forgot to mention, that i have tableview with static cells; so prepareForReuse isn't called. I have outlets for my cells, so that i've also tried to set the shadow to my cell in scrollViewDidScroll: method. Even this din't help me
I just encountered this problem. Finally I find the way to make it work.
It doesn't disappear(removed), it was just been hidden.
There we use a property zPosition of cell's layer.
From Apple docs:
The default value of this property is 0. Changing the value of this property changes the the front-to-back ordering of layers onscreen. This can affect the visibility of layers whose frame rectangles overlap.
The value of this property is measured in points.
The default value is 0. This leads top cell hides the bottom cell (say shadow). It means if you set shadow for a view to make it show in both sides and the margin before two cell is zero, only bottom shadow of the top cell will show up, the top shadow of the bottom shadow will be hidden.
When the cell goes out of the screen and then back, though the zPosition of each cell is still 0, for those cells, bottom cell hides top cell now. The hide direction is opposite to your scroll direction. This is exactly the situation you met.
So,
cell.layer.zPosition = <#value you want#>
For example, I want to show shadow of the siblings, I can set zPosition of this cell's layer to -1, then shadow of both side will appear.
zPosition of a layer decide which cell can show in the front, and which shows in the back. Like z-index in CSS.
So the solution is change the zPosition property to make it work as you expected.
In addition, you should not set cell's clipsToBounds to YES. (default value is NO)
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.
I would like to make the currently selected cell in a UICollectionView "bulge" - it should be larger than the adjacent cells.
I tried doing:
cell.transform = CGAffineTransformMakeScale(1.5, 1.5);
this indeed makes the cell larger - but it clips to the UICollectionView frame and the overlap of the cell is incorrect - the cell will overlap on top of the cell left to it - but it will be "under" the cell right to it.
I would like for it to be similar to the "Magnifying" effect in OSX dock.
How can I change the "Z" of the cell and allow it not to clip to the boundaries of the UICollectionView?
but it clips to the UICollectionView frame
Try to set clipToBounds to false for your collectionview. z-index is only for view's with the same superview.
the cell will overlap on top of the cell left to it - but it will be
"under" the cell right to it.
zPosition should help here. you can set it like this
cell.layer.zPosition = 1; //standard is 0, don't forget to set it back to zero
if you are using xcode < 5 you need to include QuartCore
#include <QuartzCore/QuartzCore.h>
Upon changing the highlight color of the cell when selected, the box drawn around the top and bottom of the table no longer clips within the table's borders.
I have tried clipsToBounds with both tableView and the cells, but with no luck.
Any solutions?
Thanks!
image of the problem >
I have a idea how to make the effect you need work, may not be the best way but you can have a try.
first check if the cell is the last cell; if so:
UIBezierPath *lastCellMask;
lastCellMask = [UIBezierPath bezierPathWithRoundedRect:cell.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(3.0, 3.0)];
CAShapeLayer *cellMaskLayer = [[CAShapeLayer alloc] init];
cellMaskLayer.frame = cell.bounds;
cellMaskLayer.path = lastCellMask.CGPath;
cell.layer.mask = cellMaskLayer;
and do the reverse for the first cell
This works for me, check if this can help u
looking at the image, try
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
The problem is that you are using grouped style for your table view. The grouped table view doesn't have the margins that you are seeing in the UI, and using clipToBounds won't help because the cells bounds are exactly the ones you are seeing when you are selecting the cell. What you could do is use the cornerRadius layer property for your cell (only the first and last cell in the section) in order to round the corners and create the desired result.
I'm working on an iOS 5 project with storyboards, and thus using dynamic table cell prototypes in IB. In one of the views, I've got a table view with variable-height cells, with the cell height calculated from the height of the contents.
tableView:heightForRowAtIndexPath: returns correct values for all cells when the table view is first displayed. All is well when scrolling down for a few items, but then something goes amiss: the actual cells seem to be correct height, including their touch areas, but their separators are rendered in the wrong places (inside cells instead of between them).
From measuring the separator placement, it appears as if cell reuse might have something to do with this. The separators for the first three cells are rendered correctly, but not the fourth one. heightForRowAtIndexPath: returns the correct height for it (125 pixels in this case), and its contained subviews are all in their right places. However, the separator is rendered only 108 pixels from the previous separator, placing it inside the 125 pixel high area of the cell.
Here's the kicker: 108px is the height of the first table cell, now out of sight and probably reused. I don't have definite proof of this, but it appears that the table view is ignoring heightForRowAtIndexPath: for these cells and is just rendering the separator according to the reused cell height.
This doesn't explain why a bunch of later, shorter cells are not rendered separators at all. But this is all I've got to go on.
Is there a workaround, an IB setting or something else that might help?
I had the same problem where the separators were showing at seemingly random positions.
It turned out the problem was that I was overriding layoutSubviews but forgot to call [super layoutSubviews]. Adding that call fixed the issue for me.
I also met this weird problem. For a custom table cell, add a layer as a separator may be a better choice.
in initWith*** method of the custom table cell class:
separator = [CALayer layer];
separator.backgroundColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor;
[self.layer addSublayer:separator];
update separator's frame in layoutSubviews method:
- (void)layoutSubviews {
CGFloat height = 1.0f;
separator.frame = CGRectMake(0.0f, self.frame.size.height - height, self.frame.size.width, height);
[super layoutSubviews];
}