Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView opaque property

Tags:

The opaque property of a UIView is by default always set to "YES". But the UIView class reference states this:

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.

Since changing the alpha of a view is quite common, especially during transitions or animations, then the above statement would imply that you must always manually set opaque to NO if you are going to change the alpha property as well.

But I have never manually adjusted opaque and haven't had any noticeable symptoms. How necessary is it to make this consideration?

like image 653
johnbakers Avatar asked May 04 '12 07:05

johnbakers


People also ask

How do you make a picture less opaque on Iphone?

Tap to select an image, shape, text box, line, arrow, drawing, or video, or select multiple objects. For a drawing, tap Drawing, then drag the Opacity slider; for any other item, tap Style, then drag the Opacity slider. You can also tap the percentage below Opacity and enter a new value.

How do you increase transparency on Iphone?

Short guide:Open the Settings app and tap Accessibility. Tap Display and Text Size. Tap the toggle switch for Reduce Transparency to turn it on.

What is reduce transparency on Iphone?

Reduce Transparency: This setting reduces the transparency and blurs on some backgrounds. Increase Contrast: This setting improves the contrast and legibility by altering color and text styling.

What is Isopaque?

A Boolean value that determines whether the view is opaque.


2 Answers

The answer is that iOS is smart enough to recognize that if your view's alpha is less than 1, it needs to draw the content behind your view, regardless of your view's opaque property.

In response to comments: from my limited experimentation, I don't think the view's opaque property has any effect. (I think the documentation is wrong.) The view's layer's opaque property does have an effect: it controls whether the CGContext passed to drawRect: has an alpha channel. If the layer's opaque property is YES, the context has no alpha channel (and is treated as if every pixel has alpha of 1.0).

Changing the view's opaque property has no effect on the layer's opaque property. This is different than (for example) the view's alpha property, which is just a wrapper for the layer's opacity property.

In theory, having documented that the opaque property allows them to optimize drawing, Apple could implement that optimization in the future. In practice, doing so would probably break a lot of apps, so they probably won't make such a change apply to apps linked against older SDKs. (They have the ability to make UIKit behave differently depending on which version the app was linked with.)

like image 93
rob mayoff Avatar answered Sep 19 '22 15:09

rob mayoff


As long as the view contents itself (not its subviews) don't have alpha you're fine. So if you init an UIImageViews with an PNG image with alpha, opaque will be set to NO automatically.

Normally you don't really need many non-opaque views. But alpha of the complete view is smth different anyway.

like image 30
calimarkus Avatar answered Sep 19 '22 15:09

calimarkus