Blurry UILabel as programmatic subview of UITableViewCell contentView

后端 未结 9 929
离开以前
离开以前 2021-02-04 02:26

I am adding a UILabel instance as a subview of my custom UITableViewCell instance\'s contentView.

When I select the cell, the row

9条回答
  •  星月不相逢
    2021-02-04 03:13

    Does -setNeedsLayout get called even for dequeued reusable cells? If so, the cell will already have the label added to the content view, and you will draw it twice, making it blurry. You can inefficiently solve this by removing all of the content view's subviews before you add your subview:

    for (UIView *subview in [[self contentView] subviews]) {
         [subview removeFromSuperview];
    }
    

    A better solution would be to provide properties on your cell subclass to let you modify the content of a reused cell as-needed, rather than rebuilding its view hierarchy from scratch.

提交回复
热议问题