Navigation with only Back Button and transparent background

℡╲_俬逩灬. 提交于 2019-12-04 10:36:21
Vizllx

That seems pretty easy, by the following code used in my app too:-

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true
self.navigationController?.view.backgroundColor = UIColor.clearColor()

Edit:-

To remove back button text:-

navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)

Swift 3.0

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.isTranslucent = true
self.navigationController?.view.backgroundColor = UIColor.clear

I don't know is there any other option or not. But in the past i have same scenario as you.

I have created custom .XIB with UIView. and Add subview it to as Navigationbar.

So, According to me the best option is , create custom .XIB with Height of UINavigation bar. and Add as subview.

Here is step how you can achieve it.

1) Take .h file , .m file and Xib of UIView with size of width 46 and height 44

2) Set constrain and layout according to your suitable design.

3) Give outlet to Back button in .h file.

4) Create one delegate in customview.h file . set method in .m file.

5) then import customview.h file in your viewcontroller.h file . As same don't forget to define delegate in viewcontrollers interface. <>

6) Now add customheaderview as subview in your Viewdidload method.

#define macro_name (Define in constantfile as macro if you don't want to write whole code again and again)

NavigationHeaderview *customView = [NavigationHeaderview CustomNavigation:self.navigationController.navigationBar.frame.origin.x y:self.navigationController.navigationBar.frame.origin.y width:self.navigationController.navigationBar.frame.size.width height:self.navigationController.navigationBar.frame.size.height];
customView.delegate=self;
[self.navigationController.view addSubview:customView];

7) Access it in your all view controller with delegate method of headerview.

Now you can do anything in navigationbar like you do in UIView.

Note:- I know it is tedious process. but it is worth when you need 3 or 4 button in navigation bar and set Action on it . or need same design layout for whole project in navigationbar..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!