iOS development-The UIView attribute hidden, opaque, alpha, opacity differences

Source: Internet
Author: User
Tags instance method

iOS Development-UIView properties hidden, opaque, alpha, opacity the alpha LCD is made up of pixel dots, each pixel can display a color value composed of the Rgba color space. A is a representation of the transparency Alpha,uiview Alpha is a floating-point value, and the range of values is 0~1.0, from full transparency to completely opaque. 1, Alpha will affect their transparency, but also affect the transparency of subview. 2. After the alpha is set to NULL, the UIView is not removed from the responder chain and can still receive the event. 3, change the alpha, the default is animated, this is because the layer in cocoa is represented by the core animation Calayer, the animation effect is Calayer's implied animation. Of course there are ways to disable this animation effect.    Hidden This property is a bool value, which is used to indicate whether the UIView is hidden and the default value is No. When the value is set to Yes: 1, the current UIView and Subview will be hidden, regardless of the subview hidden. 2. The current uiview is removed from the responder chain, and the next in the responder chain becomes the first responder   Alpha-hidden 1, the effect on Subview: Alpha affects subview transparency, Hidden also affects SubView2, hidden Uiview:alpha set to 0 can be hidden Uiview,hidden set to Yes also can hide UIView, the effect is the same, using hidden performance is high.   Opaque This property is a bool value, the default value for UIView is yes, but the default value for subclasses such as UIButton is No. Opaque indicates whether the current UIView is opaque, but the funny fact is that it doesn't make the current uiview opaque, such as if you set opaque to No, the UIView is still visible. The function is: to provide a performance optimization switch for the drawing system. If the value is yes, the drawing will treat the entire view as opaque when drawing the view. In this way, the drawing system optimizes some operations and provides system performance during the drawing process, and if set to No, the drawing system treats it and other content equally and does not perform optimization operations. For performance reasons, the default is set to Yes (meaning optimization). 1, UIView when there is a background color: and the background color is transparent (opacity is not 1 o'clock), set opaque to Yes high performance. 2, UIView with background color: and the background color transparency is 1,oThe value of Paque does not affect performance. 3, UIView no background color: The value of opaque does not affect performance.   Opacity-calayer Property Calayer in opacity is a floating-point value, with a range of values 0~1.0, from completely transparent to completely opaque. 1, opacity will affect their own transparency, but also affect the transparency of sublayer. 2. After opacity is set to NULL, Calayer will not be removed from the responder chain and will still receive the event.   How to set uiview transparent, subview opaque 1, use a translucent picture to do the background. This method can achieve the requirements, but the project should be as few as possible to add resources, can not use pictures as far as possible without pictures. 2, use Colorwithwhite:alpha: Method view.backgroundcolor = [Uicolor colorwithwhite:0.f alpha:0.5]; This is also used more methods, The parameters behind white represent grayscale, from 0-1 to black, and alpha is the transparency you want to adjust. 3. Use ColorWithRed:green:blue:alpha: Method setting Alpha is the transparency you want to adjust. 4.set the background in Xib or storyboardAdjust the transparency by opacity the slider in the background color settings graph. 5.using Colorwithalphacomponent: MethodThis is an instance method, and a Uicolor instance calls this method and returns a uicolor with transparency. Use the following method:
Uicolor *color == [color colorwithalphacomponent:0.5];









iOS development-The UIView attribute hidden, opaque, alpha, opacity differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.