UIView performance: opaque, backgroundColor, clearsContextBeforeDrawing?

后端 未结 2 812
感动是毒
感动是毒 2021-02-05 21:04

I\'m displaying opaque PNGs with UIImageViews inside of a superview with a white background color. What\'s best for performance?

UIImageView D

2条回答
  •  孤城傲影
    2021-02-05 21:47

    Assuming that your PNGs always fills the entire UIImageView, you should get the best performance using:

    opaque = YES, clearsContextBeforeDrawing = NO. In this mode backgroundColor is irrelevant. The pixels are simply replaced with the new image data.

    For transparent PNGs on a single-color background, the fastest will be:

    opaque = YES, clearsContextBeforeDrawing = YES, and backgroundColor matching whatever you need. In this case [UIColor whiteColor].

提交回复
热议问题