UIView's contentScaleFactor depends on implementing drawRect:?

前端 未结 2 1488
北荒
北荒 2021-02-14 11:42

I have stumbled on a weird thing. It looks like UIView\'s contentScaleFactor is always 1, even on Retina devices, unless you implement drawRect:<

2条回答
  •  一生所求
    2021-02-14 12:18

    Native drawing technologies, such as Core Graphics, take the current scale factor into account for you. For example, if one of your views implements a drawRect: method, UIKit automatically sets the scale factor for that view to the screen’s scale factor. In addition, UIKit automatically modifies the current transformation matrix of any graphics contexts used during drawing to take into account the view’s scale factor. Thus, any content you draw in your drawRect: method is scaled appropriately for the underlying device’s screen.

提交回复
热议问题