【问题标题】:uinavigationbar background image hides titleuinavigationbar 背景图片隐藏标题
【发布时间】:2013-11-06 06:35:17
【问题描述】:

当我向uinavigationbar 添加背景图片时,它会在uinavigationbar 上隐藏我的标题,

这是我的代码,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
       ...
       ...

     [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed: @"BarBg.png"] forBarMetrics:UIBarMetricsDefault];
}

类中的代码:

    int height = self.navigationController.navigationBar.frame.size.height;
    int width = self.navigationController.navigationBar.frame.size.width;

    UILabel *navLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    navLabel.text=@"Categories";
    navLabel.backgroundColor = [UIColor clearColor];
    navLabel.textColor = [UIColor whiteColor];
    navLabel.font = [UIFont boldSystemFontOfSize:17];
    navLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = navLabel;

编写此代码后,我无法在导航栏上看到标题,标题在导航栏图像后面。

请帮忙,提前致谢..

【问题讨论】:

    标签: ios iphone ipad uinavigationbar title


    【解决方案1】:

    而不是将标签设置为 UINavigationBar 的 titleView 添加 UILabel 作为 NavigationBar 的子视图,如下所示...

    [self.navigationController.navigationBar addSubview:navLabel];
    [self.navigationController.navigationBar bringSubviewToFront:navLabel];
    

    【讨论】:

      【解决方案2】:

      如果您只想自定义您的导航栏标题,我建议您使用外观而不是向导航栏添加标签。

           [[UINavigationBar appearance] setTitleTextAttributes:@{
                                       UITextAttributeFont: [UIFont fontWithName:yourFontName size:fontSize],
                                       UITextAttributeTextColor :[UIColor whiteColor],
      
            }];
      

      【讨论】:

        猜你喜欢
        • 2013-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多