White space before separator line into my TableView

后端 未结 8 1991
青春惊慌失措
青春惊慌失措 2020-11-30 19:49

I have a question about UITableView... I have a UITableViewController and I created a custom cell. When I visualize the tableView I see a little white space before the separ

8条回答
  •  醉话见心
    2020-11-30 20:35

    There is no white space! I entered a bug on this, Apple just closed it as "not a bug", but told me why its not a bug. I wrote a simple project that sets a color for every possible view in the app. What I see is that the color of those pixels is actually the background color of the cell itself (not the contentsView!), just as Apple had told me.

    The cell.contentView.backgroundColor is green, and the cell.background color is red (taken with Pixie):

    enter image description here

    In the end, without a separator, the cell.contentView fills the cell completely. With a separator, there is a pixel or two gap at the bottom. The separator, when inset, fills the most of the gap, but there are then some pixels of the cell showing through.

    Mystery solved!

    EDIT: It seems that depending on how you configure your Storyboard, that the contentView.backgroundColor gets "lost" or set to White. If you over ride it when supplying cells you can get the behavior your want:

        let cell = tableView.dequeueReusableCellWithIdentifier("FOO", forIndexPath: indexPath) as UITableViewCell
    
        cell.backgroundColor = UIColor.redColor()
        cell.contentView.backgroundColor = UIColor.greenColor()
    

提交回复
热议问题