Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of transparency of navigationBar in ios development

Shulou Source: shulou.com Published: 2022-06-01 04:18:58 10月02日 Update

This article will explain in detail how to solve the transparency problem of navigationBar in ios development. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

Transparency of navigationBar

If only the alpha of the navigationBar is set to 0, it is tantamount to hiding the navigationBar. As we all know, if the alpha of the parent view is set to 0, then all the child views will be transparent. Then the title of the corresponding navigationBar and the left and right buttons will disappear. This obviously does not achieve the desired effect.

(1) if you just want the navigationBar to be transparent, you can use the following methods for both buttons and captions:

[self.navigationController.navigationBar setBackgroundImage: [UIImage new] forBarMetrics:UIBarMetricsDefault]; / / set an empty background image for navigationBar to achieve transparency, and the caption buttons are all in the

If you are careful, you will find that there is a line on it like the following picture:

This requires us to do further processing, to remove the line, as follows:

Self.navigationController.navigationBar.shadowImage = [UIImage new]; / / actually this line is also controlled by image. Just set it to empty.

(2) if you want to change the effect from transparency to opacity according to the drop-down distance on the basis of transparency, then the one above seems inadequate, which requires us to adopt another method.

/ / navigationBar is a composite view, which is made up of many controls, so we can start from its interior [[self.navigationController.navigationBar subviews] objectAtIndex:0] .alpha = 0 / / here you can set alpha according to the offset of scrollView to achieve the effect of gradual transparency. This is the end of the article on "how to solve the problem of transparency of navigationBar in ios development". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Questions buttons effects methods titles articles views development more good practical careful inadequate two all content pictures basics controls articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Xiaomi Redmi MySQL