Ios ui -- set the color and transparency of NavigationBar, ui -- navigationbar

Source: Internet
Author: User
Tags transparent image

Ios ui -- set the color and transparency of NavigationBar, ui -- navigationbar

Sometimes we need to set the color of the NavigationBar of the UINavigationController to transparency. In this case, we need to use the barStyle attribute of NavigationBar:
      

Let's look at the imitation project example of the QQ space:

               


Code example: nc. navigationBar. barStyle = UIBarStyleDefault;
<Note: All the UI legends are shown below. The window. view background is green.>


1. If no background image is set:


1. UIBarStyleDefaul
Because it is the default value, you can not set the barStyle attribute.
  
2. UIBarStyleBlack
3. UIBarStyleBlackOpaque
4. UIBarStyleBlackTranslucent (Translucent)
Here 2 ~ 4 is the same:

  


2. Set a 1x1 transparent image or an empty UIImage object (You are advised to directly use the UIImage object, even the image is not required) as the background

Code example:

    

Of course, there is another premise that needs to be proposed: the following fields are not added to the instance diagram (XCode 7.2.1)

    
1. UIBarStyleDefaul
  
2. UIBarStyleBlack
3. UIBarStyleBlackOpaque
4. UIBarStyleBlackTranslucent (Translucent)

Here 2 ~ 4 is the same:
  

3. Set the black image of 1x1 to the background.


1. UIBarStyleDefaul
  
2. UIBarStyleBlack
3. UIBarStyleBlackOpaque
4. UIBarStyleBlackTranslucent (Translucent)
Here 2 ~ 4 is the same:

    

4. Set the 1x1 red image as the background

1. UIBarStyleDefaul
  
2. UIBarStyleBlack
3. UIBarStyleBlackOpaque
4. UIBarStyleBlackTranslucent (Translucent)

  

 

Appendix: issues that have not been resolved:

Because I can see that the navigation controller and status bar of the QQ space can be connected together and the color will change gradually, so I will try to change the background color of the navigation bar UINavigationBar by setting the image background;

I added a line of code:

  

The effect is as follows:

  

Then I tried not to set the background UIImage object by default or not set the background transparent image:

  

The effect is even worse:

  

 

Solution:

I don't know how the QQ space is implemented, but I will give three ideas below, two of which will be implemented in detail. If any of you have a better idea, you are welcome to exchange ideas.

The following shows the effect of a problem. The problem is solved as follows:

  

Idea 1: Define a UINavigationBar to replace the original UINavigationBar.

This can be achieved, but I am not doing it, so I am lazy.

Related Article

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.