简体   繁体   English

UINavigationBar中的透明图像

[英]transparent image in UINavigationBar

i have made a simple design in photoshop when i tried to put it in Xcode i had some problems with NavigationBar 当我尝试将其放在Xcode中时,我在photoshop中做了一个简单的设计,我在NavigationBar上遇到了一些问题

i used this code to change the UINavigationBar background image (a PNG transparent image): 我使用此代码来更改UINavigationBar背景图像(PNG透明图像):

UINavigationBar *navBar = [[self navigationController]navigationBar];
[navBar setBackgroundImage[UIImageimageNamed:@"navBar2.png"]forBarMetrics:UIBarMetricsDefault]

everything works fine but the problem is that the image appears in the navigationBar without transparency. 一切正常,但问题是图像在导航栏中显示为不透明。

please someone help me to fix the transparency issue i search everywhere without any satisfied answer 请有人帮助我解决我在各处搜索时没有任何满意答案的透明度问题
NB! 注意! Im using IOS 5 我正在使用iOS 5

您可以尝试将导航栏设置为半透明。

[navBar setTranslucent: YES];

Do you have it in your Storyboard? 您的情节提要中有吗? Try change the style of your navigation bar into black translucent. 尝试将导航栏的样式更改为黑色半透明。

What you can do is set the background color of the view of the navigationController the same as the backgrouond color of the main view. 您可以做的是将navigationController视图的背景色设置为与主视图的背景色相同。

//Set your view's background color    
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"view_background"]]];

//Set your custom image for the navigationController
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed: @"navigation_bar_image"] forBarMetrics:UIBarMetricsDefault];

//And then set the background color of the navigationController the same as the one of the view
[self.navigationController.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"view_background"]]];
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationBar setShadowImage:[UIImage new]];
[self.navigationBar setTranslucent:YES];

And make sure you set up tint color to default. 并确保将色调颜色设置为默认颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM