Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need I set UIVIew.opaque to NO explicitly if I use clearColor as backgroundColor?

Tags:

ios

uiview

Need I write:

view.opaque = NO;

for every view with transparent backgroundColor or less-than-1 alpha?

From the doc it seems so:

An opaque view is expected to fill its bounds with entirely opaque content—that is, the content should have an alpha value of 1.0. 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.

But in fact, I never do that and seldom see other people do that, and the code works just fine.

If it turns out I do need set opaque to NO, it is time for me the dig out all the bad code and rectify them.

like image 647
an0 Avatar asked Dec 18 '25 10:12

an0


1 Answers

You should set this explicitly, although if you are inflating from a nib, you can just set the property in InterfaceBuilder/Xcode. This property serves as a shortcut flag for the graphics context so it doesn't have to try to infer whether or not your view is transparent.

The code will still work, but the runtime has to make the inference. Also, because of the way iOS invalidates certain areas of the window without invalidating others, you can get some funky behavior from time-to-time if your view is marked opaque and it really isn't.

like image 177
James Avatar answered Dec 20 '25 00:12

James



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!