swift5 搭建 tabBar (1) 完整教程【下期在这个基础上中间弄个+号】
2023-09-27 14:27:38 时间
效果
前期需要的配置
https://blog.csdn.net/mp624183768/article/details/108935803
继续配置 为了让背景变成白色 弄一个全局的基类
//
// BaseViewController.swift
// News
//
// Created by liuan on 2020/10/6.
//
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .white
// Do any additional setup after loading the view.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
主界面
//
// MyTabBarController.swift
// News
//
// Created by liuan on 2020/10/5.
//
import UIKit
class MyTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let tabbar = UITabBar.appearance()
tabbar.tintColor = UIColor(red: 245 / 255.0, green: 90 / 255.0, blue: 93 / 255.0, alpha: 1.0)
//
//添加子控制器
addChildViewControllers()
}
///添加子控制器
func addChildViewControllers(){
setChildViewController(HomeViewController(), title: "首页", imageName: "home_tabbar_32x32_", selectedImageName: "home_tabbar_press_32x32_")
setChildViewController(VideoViewController(), title: "视频", imageName: "video_tabbar_32x32_", selectedImageName: "video_tabbar_press_32x32_")
setChildViewController(HuoshanViewController(), title: "小视频", imageName: "huoshan_tabbar_32x32_", selectedImageName: "huoshan_tabbar_press_32x32_")
setChildViewController(MineViewController(), title: "我的", imageName: "mine_tabbar_32x32_", selectedImageName: "mine_tabbar_press_32x32_")
}
///初始化主控制器
func setChildViewController(_ childController: UIViewController,title:String,imageName:String,selectedImageName:String) {
//设置tabbar 文字图片
childController.tabBarItem.image = UIImage(named: imageName)
childController.tabBarItem.selectedImage = UIImage(named: selectedImageName)
childController.tabBarItem.title = title
//添加导航控制为 TabController 的子控制器
let navVc = MyNavigationController(rootViewController: childController)
addChild(navVc)
}
}
其他的四个内容都是一样的空的 我就贴一个
import UIKit
class MineViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.white
}
}
至于资源文件和完整教程大家如果感兴趣可以到
https://www.yzdzy.com/detail.php?id=11526
这里5元购买下完整教程
相关文章
- Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) JAVA日志的前世今生 .NET MVC采用SignalR更新在线用户数 C#多线程编程系列(五)- 使用任务并行库 C#多线程编程系列(三)- 线程同步 C#多线程编程系列(二)- 线程基础 C#多线程编程系列(一)- 简介
- Android基础新手教程——1.5.2 Git之使用GitHub搭建远程仓库
- ActiveReports 9实战教程(2): 准备数据源(设计时、执行时)
- 分布式系列教程(06) -分布式Redis缓存 (集群)
- 这里有篇Charles详细教程,看完后就可以把Fiddler卸载了
- 【简单易懂的AMV图文教程-2】VEGAS基础进阶——认识关键帧
- Godaddy新手教程
- Django 博客开发教程 7 - 在 Django Admin 后台发布文章
- SwiftUI AI之如何使用 DALL-E API——生成人脸(教程含源码)
- SwiftUI基础组件之Link打开URL网页链接 (教程含源码)
- SwiftUI如何优雅的删除List列表中元素(教程含源码)
- SwiftUI ScaledMetric 基础使用(教程含代码)
- SwiftUI基础之Form与Picker和DataPicker组合使用(教程含源码)
- Flet教程之 19 VerticalDivider 分隔符组件 基础入门(教程含源码)
- Python教程之使用 Python 识别加密的 PDF 文档和解密受 PDF
- SwiftUI 动画之如何检测动画结束并执行调用 (教程含源码)withAnimation
- SwiftUI 内功GCD教程之DispatchGroup基础使用实现同步更新(教程含源码)
- 【PyTorch教程】07-PyTorch如何使用多块GPU训练神经网络模型
- Arctime制作视频字幕教程
- 软件JLink安装包及其基础使用教程 资源下载
- 基于Linux(Ubuntu20.04)初步搭建k8s集群基础,详细教程