Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 383 Vote(s) - 3.38 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change color of Back button in navigation bar

#1
I am trying to change the color of the Settings button to white, but can't get it to change.

I've tried both of these:

navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
navigationItem.backBarButtonItem?.tintColor = UIColor.whiteColor()

but no change, it still looks like this:

![enter image description here][1]

How do I make that button white?


[1]:
Reply

#2
In SwiftUI, do the following:

Define a BackButton struct:
```
struct BackButton: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
Button(action: {
presentationMode.wrappedValue.dismiss()
}) {
HStack {
Image(systemName: "chevron.left")
.foregroundColor(.white)
Text("Back")
.foregroundColor(.white)
}
}
}
}

```

In the second view, use it as follows:
```
struct SecondView: View {
var body: some View {
VStack {
Text("Second View")
}
.navigationBarTitle("Second View", displayMode: .inline)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
BackButton()
}
}
}
}
```
Reply

#3
For some reason it isn't working for me programmatically. However setting it in the storyboard works every time.

[![enter image description here][1]][1]


[1]:
Reply

#4
**Swift 5 Updated**

If you need to set `Back` button color globally, you could simply use:

UIBarButtonItem.appearance().tintColor = Asset.pureWhite.color

Then you do not need to set back button background color on each view controller. If you use this one you **COULD NOT SET BACK BUTTON COLOR ON ANOTHER VIEW CONTROLLER**

**BUT**

If you need to set Back button color on view controller or change on another view controller do not use above method. You could use:

let appearance = UINavigationBarAppearance()
appearance.titleTextAttributes = [.font:FontFamily.BatonTurbo.medium.font(size: 20),
.foregroundColor: Asset.pureWhite.color] // Naviagtion Title attributes
appearance.backgroundColor = .red // Navigation bar background color

self.navigationItem.standardAppearance = appearance
self.navigationItem.scrollEdgeAppearance = appearance
self.navigationItem.compactAppearance = appearance

navigationController?.navigationBar.tintColor = .green // Back button color

Reply

#5
Swift 5.5
---------

**Change complete app theme**

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Set for app
UINavigationBar.appearance().tintColor = .white
return true
}

**Change specific controller**

let navController = UINavigationController.init(rootViewController: yourViewController)
navController.navigationBar.tintColor = .red

present(navController, animated: true, completion: nil)

Reply

#6
If you tried many times but could not work, you may try :
```
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = .red
```
Actually, I tried many times, only found this way will work.
Reply

#7
I'm using this in swift 5 and worked for me

navigationItem.backBarButtonItem?.tintColor = UIColor(named: "uberRed")
Reply

#8
**Swift 5.3:**

UINavigationBar.appearance().backIndicatorImage = UIImage(named: "custom-back-image")
UINavigationBar.appearance().backIndicatorTransitionMaskImage = UIImage(named: "custom-back-image")
Reply

#9
self.navigationController?.navigationBar.tintColor = UIColor.black // to change the all text color in navigation bar or navigation
self.navigationController?.navigationBar.barTintColor = UIColor.white // change the navigation background color
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.black] // To change only navigation bar title text color
Reply

#10
I prefer custom NavigationController rather than setting global ui, or put in ViewController.

Here is my solution
```swift

class AppNavigationController : UINavigationController {

override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}

override func viewWillAppear(_ animated: Bool) {

}

}
extension AppNavigationController : UINavigationControllerDelegate {

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
let backButtonItem = UIBarButtonItem(
title: " ",
style: UIBarButtonItem.Style.plain,
target: nil,
action: nil)
backButtonItem.tintColor = UIColor.gray
viewController.navigationItem.backBarButtonItem = backButtonItem
}

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {

}

}

```
Also you don't need to mess with Apple Api like **EKEventEditViewController**,**PickerViewController** and so on if you use global settings ui like ```UIBarButtonItem.appearance().tintColor = .white```
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through