ios cell highlight color clipstobounds - ios

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.

Related

Shadow not showing for UITableVIewCell contains UIImageView

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.

How to customise the UITableView's Separator View?

I have a problem of the implementation of UITableViewCell's separator.
As you can see from the screenshot, there is a white gap visible before the separator, I think that is because I set the bg colour of the cell as light grey and also I put the inset of the separator as 53.
My first attempt was instead of using the separator, I was trying to draw the lines at the end of the cell by my self. But since on selection of the row the content of the row get updated, and there is a lot of issue regarding the calculation of the height of the cell.
So basically it is really hard for me to draw the line pixel precise at the end of the cell.
This left me the option to access the cell's separator's view, which currently not aware of any easy way, and fill the gap with my default background colour of the table.
My question is, how can I access the separator view
Or
Do I have any other alternatives to implement what I want?
Thank you very much.
UITableView doesn't provide APIs to access or modify the cells separator view directly. However, it has methods to change it's color, style, etc. Most of the times, though, the only solution for a custom separator is to draw it yourself, or better, to set the cell's backgroundView property to a simple view with a line subview or layer in it (a subview, although has some overhead, gives you the flexibility of autoresizing automatically using autoresizing masks or auto layout).
e.g.
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.bounds];
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backgroundView.bounds) - 1, CGRectGetWidth(backgroundView.bounds), 1.0f];
[lineView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin)];
[backgroundView addSubview:lineView];
cell.backgroundView = backgroundView;
Use this workaround:
Put UIImageView at bottom edge of cell and you can set image as per your requirement
STEP 1: Set divider as per image
STEP 2: Set Separator style to none
Since iOS 7 you can use this
cell.separatorInset = UIEdgeInsetsZero;

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.

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

Changing corner radius of the cells insie a grouped UITableView

After hours of googling I am wondering if it is possible to change the corner radius of a grouped UITableView.
I tried
hoursTable.layer.cornerRadius = 5.0;
but nothing seems to change.
Make sure clip sub views of table view alon with ur code
hoursTable.layer.cornerRadius = 5.0;
by code [hoursTable setClipsToBounds:YES];
hoursTable.layer.cornerRadius = 5.0;
[hoursTable setClipsToBounds:YES];
Are you sure use <QuartzCore/QuartzCore.h> framework in your app
your method (hoursTable.layer.cornerRadius = 5.0; ) only give you rounded corners without having to add your tableview to a superView or clipping it.
also use
[hoursTable setClipsToBounds:YES];
this is work only ios 3....if you work ios 4 or ios 5x then see SO answer
I would recommend to
1) make a subclass of UITableViewCell and set the background color clear
2) make a subclass of UITableView and set the separator color clear
3) use this cells in the tableview
now here is an important method t be implemented in UITableViewCell subclass
in
- (void)drawRect:(CGRect)rect method try to make a bezier path accordingly to fill and stroke path as far your corner radius and background color...
the content rect you can get by self.contentView.frame in what you have to draw your new bezier path.

Resources