tabBarController控制导航栏的字体大小、颜色
时间: 2023-08-07 18:03:40 浏览: 56
可以在tabBarController的子控制器中通过以下方法来控制导航栏的字体大小和颜色:
1. 字体大小:
```
// 设置导航栏标题字体大小
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.0f]}];
```
2. 字体颜色:
```
// 设置导航栏标题字体颜色
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];
```
需要注意的是,以上代码需要在子控制器的viewDidLoad方法中实现,才能起到对应的效果。
相关问题
swift语言跳转页面隐藏tabbar导航栏返回时出现tabbar导航栏
在 Swift 语言中,可以使用以下代码隐藏 TabBar 导航栏:
```swift
self.tabBarController?.tabBar.isHidden = true
```
这将隐藏 TabBar 导航栏。然而,当你跳转到另一个页面并返回时,TabBar 导航栏可能会出现。为了避免这种情况,可以使用以下代码:
```swift
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.tabBarController?.tabBar.isHidden = false
}
```
这将在每次视图将要显示和将要消失时隐藏和显示 TabBar 导航栏。这样,即使你从另一个页面返回,TabBar 导航栏也不会出现。
用Objective-c纯代码编写一个顶部和底部的导航栏
以下是使用Objective-c纯代码编写一个顶部和底部的导航栏的示例代码:
顶部导航栏:
```
// 创建导航栏
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
// 创建导航栏标题
UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"Title"];
navigationBar.items = @[navigationItem];
// 添加导航栏到视图中
[self.view addSubview:navigationBar];
```
底部导航栏:
```
// 创建标签栏控制器
UITabBarController *tabBarController = [[UITabBarController alloc] init];
// 创建标签控制器1
UIViewController *viewController1 = [[UIViewController alloc] init];
viewController1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Item 1" image:nil tag:0];
// 创建标签控制器2
UIViewController *viewController2 = [[UIViewController alloc] init];
viewController2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Item 2" image:nil tag:1];
// 将标签控制器添加到标签栏控制器中
tabBarController.viewControllers = @[viewController1, viewController2];
// 添加标签栏控制器到视图中
[self.view addSubview:tabBarController.view];
```
以上代码可以根据自己的需求进行修改和调整。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)