UIView performance: opaque, backgroundColor, clearsContextBeforeDrawing?

后端 未结 2 782
感动是毒
感动是毒 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:38

    If you set UIView's opaque property to YES, you must ensure your drawing completely fills the view with no transparency. So, you need to set a white background colour (a clear one won't work, because that's not opaque).

    I don't think you want to change the defaults for your image view, but you should ensure that your PNGs do not have any transparency (that is, have no alpha channel; you can check this in Preview's image inspector; ensure it doesn't say 'Has Alpha'.). I believe UIImageView will do the right thing if you give it an opaque image.

    Depending on what's in the background, you might get better performance with opaque = YES and a white background for your image views, (to prevent redrawing parts of the parent view) but I wouldn't start that way.

提交回复
热议问题