开发者

How to Make UITableview cells and UIButton's shape with new shape other than rect

开发者 https://www.devze.com 2023-04-05 12:15 出处:网络
Is that possible to change the shape of the cells.. That means any polygon shape other 开发者_如何转开发than rectangle, round rectangle.

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 of r * 2.
  • Set [UIColor clearColor] as background color.
  • In the drawRect: method, draw your shape.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号