How to Make UITableview cells and UIButton's shape with new shape other than rect
Is that possible to change the shape of the cells.. That means any polygon shape other 开发者_如何转开发than rectangle, round rectangle. and also UIButton's shape
Create a table view with UITableViewStylePlain
.
After this use:
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Then subclass the UITableViewCell
class and in the drawRect:
method you can draw any shape you would like to.
Views in iOS (including table cells) are always rectangular. So what you need to do is:
- Create a custom
UITableViewCell
(there are lots of examples and tutorials). - When calculating the cell size, you need to calculate the bounding box of your shape. For example, if you want to draw a circle with radius
r
, you return a height ofr * 2
. - Set
[UIColor clearColor]
as background color. - In the
drawRect:
method, draw your shape.
精彩评论