how to get rounded edges on UITableViewCell's in a manner that allows cell background color to be user selected? (but not using the GROUPED mode)

谁都会走 提交于 2019-11-29 03:27:16

问题


Is there a way to get rounded edges on UITableViewCell's in a manner that:

  1. allows cell background color to be user selected/customised at run time (cells may not all have the same background color)
  2. not using the UITableView "GROUPED" mode

So I'm assuming this means I can't use the normal image approach here to get rounded edges, as in this case it would not allow for requirement 1 above


回答1:


Well, it sounds like you should give using CALayer a try. Since a UITableViewCell is a UIView subclass, you can manipulate its CALayer property.

So, first, make sure to #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 you create the cell. (If you are trying to create an effect like in a grouped table, I suppose you will want to manipulate only the first and last cells.) This should give the cell rounded corners. By manipulating the CALayer, you might be able to create the effect you want.

Also, check out this answer for how to do this to only some of the corners.



来源:https://stackoverflow.com/questions/7720856/how-to-get-rounded-edges-on-uitableviewcells-in-a-manner-that-allows-cell-backg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!