UITableViewCell's contentView's width with a given accessory type

前端 未结 3 1608
无人共我
无人共我 2020-12-09 03:19

On an iPhone, how do you figure out the width of a table view cell\'s content view when it is showing a certain accessory view (disclosure indicator, etc)?

I need th

相关标签:
3条回答
  • 2020-12-09 03:55

    Personally, I would just hard code the values -- simpler and things will break in a predictable way.

    But were I to do this programmatically, I would create a UITableViewCell, set up the editing properties / accessory views you need to measure, and then ask it how big its contentView is.

    Of course I would probably heavily cache this -- doing allocations when asking UITableView asks you for height information sounds to me like it would be slow (check with a profiler first though, as always).

    0 讨论(0)
  • 2020-12-09 03:58

    I would have a subclass of UITableViewCell that holds all its subelements. You can cange the frame of certain elements when the cell enters and exists editing mode. There is a good example of this in Apple's Table View Programming guide under the section on creating a custom table view cell.

    0 讨论(0)
  • 2020-12-09 04:00

    I believe the UITableViewCell's contentView property is the view that contains your labels etc., so the width of that should be your available size to use.

    0 讨论(0)
提交回复
热议问题