How to draw an UIImage or directly in -drawRect:?

前端 未结 2 592
情深已故
情深已故 2020-12-05 02:13

I have an UIImage which I want to draw on a UIView. But instead of creating an UIImageView and adding this as a subview, I want to ove

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 02:20

    BTW, you shouldn't load the image file in the drawRect method. Because the method is called whenever the view is required to update. Therefore, it (of course, loading procedure) may be called many many times during running. (Furthermore, OS2.x's imageNamed method has a bug -- not cached the image and leaked it.)

    Therefore, you'd better to load the file in the initialization method, not in the drawRect.

提交回复
热议问题