How can I change the back button of a certain navigation controller. I have tried to use
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.backBarButtonItem?.tintColor = UIColor.red
}
I know that if i use navigationController it will change the back button tint color on all of my view controllers.
Try this!!
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = .red
}
override func willMove(toParent parent: UIViewController?) {
self.navigationController?.navigationBar.tintColor = // original color
}
}
Related
I need the navigation bar to become transparent. Here is what i have put in my ViewController:
class ViewController: UIViewController {
#IBOutlet weak var navbar: UINavigationBar!
override func viewDidLoad() {
super.viewDidLoad()
navbar.isTranslucent=true
navbar.shadowImage = UIImage()
navbar.backgroundColor = UIColor.clear
}
According to debug view hierarchy UIVisualEffectBackdropView, UIVisualEffectSubview and UIVisualEffectSubview(yes two of them) are preventing it from becoming transparent.
Ps: I am not using a Navigation Controller.
How can i fix it?
If you build with the lastest beta iOS 13.4 and XCode 11.4, the xmhafiz answer won't work anymore.
I've found another way, maybe it's just a bug in the beta software, but I'm writing it down there, just in case
import UIKit
class TransparentNavBar :UINavigationBar {
override func awakeFromNib() {
super.awakeFromNib()
self.setBackgroundImage(UIImage(), for: .default)
self.shadowImage = UIImage()
self.isTranslucent = true
self.backgroundColor = .clear
if #available(iOS 13.0, *) {
self.standardAppearance.backgroundColor = .clear
self.standardAppearance.backgroundEffect = .none
self.standardAppearance.shadowColor = .clear
}
}
}
This three lines should be enough to make your UINavigationBar transparent.
override func viewDidLoad() {
super.viewDidLoad()
// make transparent the navbar
navbar.setBackgroundImage(UIImage(), for: .default)
navbar.shadowImage = UIImage()
navbar.isTranslucent = true
}
Is it possible to create a clear UINavigationBar class with isTranslucent = false ?
One way to do this is to change properties of UINavigationController on the viewDidLoad method of your viewController as follows :
override func viewDidLoad() {
super.viewDidLoad()
if let nav = self.navigationController {
nav.navigationBar.setBackgroundImage(UIImage(), for: .default)
nav.navigationBar.shadowImage = UIImage()
nav.navigationBar.isTranslucent = true
}
}
Simple question, but I can't find any answers... How I can change corner radius of NSCollectionViewItem instance?
view of NSCollectionViewItem doesn't have layer by default. You need to set wantsLayer to true, for example:
import Cocoa
class TestCellItem: NSCollectionViewItem {
override func viewDidLoad() {
super.viewDidLoad()
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.red.cgColor
}
override func viewDidLayout() {
super.viewDidLayout()
view.layer?.cornerRadius = 20
}
}
I have the following SearchController:
class SearchController: UITableViewController, UISearchResultsUpdating
The implementation works well, but I have to tap on the search bar to start searching every time I load the controller. What I'd like is to activate the search bar once SearchController is loaded. I have tried with:
override func viewDidLoad() {
super.viewDidLoad()
...
...
self.resultSearchController.searchBar.becomeFirstResponder()
}
I also tried with:
override func viewDidAppear(animated: Bool) {
self.resultSearchController.searchBar.becomeFirstResponder()
}
But the search bar remains deactivated and the keyboard won't show up. What am I missing? Thanks!
This works (not sure why it's not working for you):
class ViewController: UIViewController {
let mySearchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.titleView = mySearchController.searchBar
mySearchController.hidesNavigationBarDuringPresentation = false
mySearchController.searchBar.becomeFirstResponder()
}
}
If you are using PFLogInViewController with the PFLogInFieldsSignUpButton option enabled how do you customise the look of the PFSignUpViewController?
You need to subclass PFSignUpViewController, and perform your layout customisations in viewDidLoad and viewDidLayoutSubviews.
class SpuggySignUpViewController: PFSignUpViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Customisation here
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// More customisation here
}
}
To get your custom version of PFSignUpViewController presented by the PFLoginViewController, just instantiate it, and set it in the PFLoginViewController.
let loginController = PFLoginViewController()
let customSignupController = SpuggySignUpViewController()
loginController.signUpController = customSignupController
// Now show your login Controller