How to draw in contentView UITableViewCell?

I am trying to draw a string on a custom UITableViewCell. When I draw inside an overridden drawRect and use the current graphics context, I see nothing.

I know that I don’t see anything, because draw rect refers to the UIView, and not to the contentView. So my question is, how can I use content presentation using CG? Say capturing a graphics context in a contentView?

+3
source share
3 answers

I found the answer here . Basically, the ABTabeViewCell superclass sets the context so you can easily draw the drawContentView function.

-1
source

, , , UIView iot UITableViewCell . , .

+4

- ( , , ), "-" (.. drawRect) , "contentView" , . , , cell.backgroundView cell.selectedBackgroundView, ...

cell.backgroundView, cell.contentView, ( , , cell.selectedBackgroundView).

, , :

  • Use cell.contentView to display a custom view without any preparation.
  • Use cell.backgroundView and cell.selectedBackgroundView to show a fancy background for your cell ...

Or:

  • Make your custom view flexible enough to display both the selected and unselected state, and use 2 instances of your custom view: one in cell.backgroundView and one in cell.selectedBackgroundView
0
source

Source: https://habr.com/ru/post/1718670/


All Articles