UIView: opaque vs. alpha vs. opacity

前端 未结 2 804
失恋的感觉
失恋的感觉 2020-12-07 10:28

How do opaque alpha and the opacity of the background work together for a UIView and what are the differences between them?

UIView http://i

2条回答
  •  再見小時候
    2020-12-07 11:06

    To the very good answer by deanWombourne it's worth to add that, unless you don't draw your own content using the drawRect: method, the opaque property has no effect.

    Apple's doc:

    You only need to set a value for the opaque property in subclasses of UIView that draw their own content using the drawRect: method. The opaque property has no effect in system-provided classes such as UIButton, UILabel, UITableViewCell, and so on.

    If you draw your own content, keep in mind, that opaque is just a hint

    This property provides a hint to the drawing system as to how it should treat the view.

    and some more guidelines from the same Apple's doc:

    If the view is opaque and either does not fill its bounds or contains wholly or partially transparent content, the results are unpredictable. You should always set the value of this property to NO if the view is fully or partially transparent.

提交回复
热议问题