How to get rounded edges on a UITableViewCell in a way that allows you to select the background color of a cell? (but not using GROUPED mode)

Is there a way to get rounded edges on a UITableViewCell so that:

  • allows you to select the background color of the cell that the user selects / sets at runtime (cells may not have the same background color)
  • do not use UITableView "GROUPED" mode

Therefore, I assume that this means that I can not use the usual approach to the image here to get rounded edges, since in this case it will not allow to require 1 above

+7
source share
1 answer

Well, it looks like you should try using CALayer. Since UITableViewCell is a subclass of UIView, you can control its CALayer property.

So first, make sure that #import <QuartzCore/QuartzCore.h>

Then do something like for example

 [cell.layer setCornerRadius:7.0f]; [cell.layer setMasksToBounds:YES]; [cell.layer setBorderWidth:2.0f]; 

when creating a cell. (If you are trying to create an effect like in a grouped table, I suppose you only need to manipulate the first and last cells.) This should result in rounded corners of the cell. By controlling CALayer, you can create the desired effect.

Also, check out this answer on how to do this with only some of the angles.

+55
source

All Articles