1,导航栏上面添加按钮
1.1,根据文字添加
let rightBarBtn = UIBarButtonItem.init(title: "right", style:
UIBarButtonItemStyle.plain, target: self, action: #selector(action_riht))
self.navigationItem.rightBarButtonItem = rightBarBtn
//1.2,系统样式添加
let leftBarBtn = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(action_left))
//1.3,图片方式添加
let image = UIImage(named:"icon_iPad-29")?.withRenderingMode(.alwaysOriginal)
let leftBarBtn2 = UIBarButtonItem.init(image: image, style: UIBarButtonItemStyle.done, target: self, action: #selector(action_left))
self.navigationItem.leftBarButtonItem = leftBarBtn2
// self.navigationItem.leftBarButtonItems = [leftBarBtn,leftBarBtn2]
2,设置导航栏的背景颜色
self.navigationController?.navigationBar.barTintColor = UIColor.brown
3,设置导航栏按钮字体颜色
self.navigationController?.navigationBar.tintColor = UIColor.cyan
4,设置标题样式与颜色(通过导航栏字典的方式)
self.navigationController?.navigationBar.titleTextAttributes =
[NSAttributedStringKey.foregroundColor:
UIColor.yellow,NSAttributedStringKey.font:UIFont.systemFont(ofSize: 20)]
5,设置返回按钮的图片,不影响侧滑返回
// let image = UIImage(named:"icon_iPad-29")?.withRenderingMode(.alwaysOriginal)
// let navBar = self.navigationController?.navigationBar
// navBar?.backIndicatorImage = image;
// navBar?.backIndicatorTransitionMaskImage = image;
6,设置导航栏的背景图片
self.navigationController?.navigationBar
.setBackgroundImage(UIImage.init(named: "icon_iPad-29"), for: UIBarMetrics.default)
7,清除导航栏下面的线条
self.navigationController?.navigationBar.shadowImage = UIImage.init()
let isTest = false
if isTest {
8,隐藏导航栏
self.navigationController?.navigationBar.isHidden = true
9,导航跳转
//9.1 压栈
let secondVC = SecondViewController.init()
self.navigationController?.pushViewController(secondVC, animated: true)
//9.2 出栈
//出栈到上级界面
self.navigationController?.popViewController(animated: true)
//出栈到顶端
self.navigationController?.popToRootViewController(animated: true);
}
网友评论