首页 文章

UINavigationBar中的透明图像

提问于
浏览
0

我在photoshop中做了一个简单的设计,当我试图把它放在Xcode中时,我遇到了一些NavigationBar的问题

我使用此代码更改UINavigationBar背景图像(PNG透明图像):

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

一切正常但问题是图像出现在导航栏中没有透明度 .

请有人帮我修复透明度问题我搜索到处都没有任何满意的答案
NB!我正在使用IOS 5

4 回答

  • 3
    [self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationBar setShadowImage:[UIImage new]];
    [self.navigationBar setTranslucent:YES];
    

    并确保将色调颜色设置为默认值 .

  • 0

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

    [navBar setTranslucent: YES];
    
  • 0

    你在故事板里有吗?尝试将导航栏的样式更改为黑色半透明 .

  • 0

    您可以做的是将navigationController视图的背景颜色设置为与主视图的backgrouond颜色相同 .

    //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"]]];
    

相关问题