gpt4 book ai didi

ios - uinavigationbar 背景图像隐藏标题

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:45 25 4
gpt4 key购买 nike

当我将背景图片添加到 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;

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

请帮忙,提前致谢..

最佳答案

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

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

关于ios - uinavigationbar 背景图像隐藏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19805607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com