How to Add a Left Bar Button Without Overriding the Natural Back Button

How do I add a left bar button without overriding the natural back button?

By default, the leftItemsSupplementBackButton property is false. In this case,
the back button is not drawn and the left item or items replace it. If you
would like the left items to appear in addition to the back button (as opposed to instead of it) set leftItemsSupplementBackButton to true.

@property(nonatomic) BOOL leftItemsSupplementBackButton

you can use something like this

navigationItem.leftBarButtonItem = editButton
//or
navigationItem.leftBarButtonItems = [editButton]

self.navigationItem.leftItemsSupplementBackButton = true

Navigation Left bar button item with back button

The presence of custom left bar button items causes the back button to be removed in favor of the custom items. Set navigationItem property leftItemsSupplementBackButton to true will display back button also with your custom left bar item.

self.navigationItem.leftItemsSupplementBackButton = true

Check Apple Documentation on leftItemsSupplementBackButton for more details.

Use UINavigationBar appearance back icon for custom button?

UINavigationBar.appearance().backIndicatorImage is an optional value, therefore you won't be able to get the system default chevron from this. Rather, the system will use the image provided here if not null, otherwise revert to the system default.

If targeting iOS 13+, you can make use of Apple's SF Symbols, in particular the back button icon is referred to as chevron.left. To use this, call UIImage(systemName: "chevron.left"). For earlier versions of iOS, you'll have to use an image set asset. You could target all versions of iOS using if #available(iOS 13.0, *) { ... } else { ... }, where you display the system image if on iOS 13+ for improved UI appearance.

func addBackButton() {
let backButton = UIButton(type: .custom)
if #available(iOS 13.0, *) {
backButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
}
else {
backButton.setImage(UIImage(named: "backChevon"), for: .normal)
}
backButton.imageView?.contentMode = .scaleAspectFit
backButton.setTitle("Back", for: .normal)
backButton.setTitleColor(backButton.tintColor, for: .normal)

self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: backButton)
}

Add bar button in UINavigationbar

UINavigationItem has a property leftItemsSupplementBackButton, you can use it.

leftItemsSupplementBackButton
A Boolean value indicating whether the left items are displayed in addition to the back button.

@property BOOL leftItemsSupplementBackButton

Discussion
Normally, the presence of custom left bar button items causes the back button to be removed in favor of the custom items. Setting this property to YES causes the items in the leftBarButtonItems or leftBarButtonItem property to be displayed to the right of the back button—that is, they are displayed in addition to, and not instead of, the back button. When set to NO, the items in those properties are displayed instead of the back button. The default value of this property is NO.

From UINavigationController Class Reference.

UIBarButtonItem *leftBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(logout)];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
self.navigationItem.leftItemsSupplementBackButton = YES;

How do I change the title of the back button on a Navigation Bar

This should be placed in the method that calls the ViewController titled "NewTitle".
Right before the push or popViewController statement.

UIBarButtonItem *newBackButton = 
[[UIBarButtonItem alloc] initWithTitle:@"NewTitle"
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[[self navigationItem] setBackBarButtonItem:newBackButton];
[newBackButton release];

add navigation bar but there is no back button

You are pushing new NavigationController(say Nav.B) to the existing one(Nav.A).

Each navigation controller keeps different navigation stack. The back button is visible when you add viewcontroller to Navigation controller. Read more about UINavigationController.

For your current scenario, you could delete the second navigation controller(i think it not essential) & connect direct segue to ListTableViewController

So this

let controller = (segue.destination as! UINavigationController).topViewController as! ListTableViewController

becomes

let controller = segue.destination as! ListTableViewController

When you need large titles(available 11+), you can add this line in viewDidLoad()

navigationController?.navigationBar.prefersLargeTitles = true

And if it needed only for this Viewcontroller, add in viewWillDisappear() or viewDidDisappear()

navigationController?.navigationBar.prefersLargeTitles = false

How to add Back Button without using AppBar in Flutter?

Simran, this is a little tricky but it is possible with the combination of Stack, SingleChildScrollView and AppBar. Here is quick example demonstrating this,

return Scaffold(
body: Stack(children: <Widget>[
Container(
color: Colors.white,// Your screen background color
),
SingleChildScrollView(
child: Column(children: <Widget>[
Container(height: 70.0),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
buildRow('This is test row.'),
])
),
new Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: AppBar(
title: Text(''),// You can add title here
leading: new IconButton(
icon: new Icon(Icons.arrow_back_ios, color: Colors.grey),
onPressed: () => Navigator.of(context).pop(),
),
backgroundColor: Colors.blue.withOpacity(0.3), //You can make this transparent
elevation: 0.0, //No shadow
),),
]),
);

demo

Note: You can make the AppBar completely transparent. However, you'll need to design your widgets accordingly to make sure back button is visible. In the example above, i just set the opacity.

Hope this helps. Good luck!

how to have the back navigation bar without the navigatin bar

add this to the main view controller

override func viewDidLoad() {
super.viewDidLoad()

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

self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
}

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

self.navigationController?.setNavigationBarHidden(true, animated: true)
}

override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)

self.navigationController?.setNavigationBarHidden(false, animated: true)
}


Related Topics



Leave a reply



Submit