ios – UINavigationController透明度?
2020年02月18日
作者:佚名
我试图让我的导航栏变为100%透明,这样UINavigationButtonItems只能看到,背景(通常是白色)应该显示背景图像.
我试过了
HomeNavigationController *navBar = [[HomeNavigationController alloc] initWithRootViewController:self.myViewController]; [navBar.navigationBar setBarTintColor:[UIColor clearColor]]; [navBar.navigationBar setTranslucent:YES];
虽然似乎都不起作用.
编辑:
运用
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; self.navigationController.navigationBar.shadowImage = [UIImage new]; self.navigationController.navigationBar.translucent = YES; self.navigationController.view.backgroundColor = [UIColor clearColor];
我可以看到它按预期工作,但现在这些项目也是看不见的.
FINALEDIT:啊,上面的代码可以工作,只是确保你没有先测试就不对外观进行任何其他改动!
实际执行预期的代码:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
或者,您可以设置透明图像,但这更有意义.如果您不想要代表边框的线,则需要原始编辑中显示的其余代码.
解决方法
有一个技巧.
只需将透明图像设置为导航栏背景即可.
只需将透明图像设置为导航栏背景即可.
UIImage *fakeImage = [UIImage imageNamed:@"transparentImage"]; [navigationBar setBackgroundImage:fakeImage forBarMetrics:UIBarMetricsDefault];
要么
[navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
以上是来客网为你收集整理的ios – UINavigationController透明度?全部内容,希望文章能够帮你解决ios – UINavigationController透明度?所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。