I notice something strange happens to one of my view controller: the back button disappears, yet it's possible to go back to previous view controller by tapping the top left corner (i.e where the button should reside).
In my entire file there's no line that set self.navigationItem.hidesBackButton to YES; also NSLog prints 0 as self.navigationItem.hidesBackButton's value in viewDidLoad.
This occurs in both the simulator and real device. Any ideas?
Oh dear. In the implementation of the previous view controller, I accidentally set self.title to #"", which causes this annoying bug.
Remove this line solves the problem.
I had a recursive navigation controller, and this also happened to me, I used this code to fix it:
self.navigationItem.leftItemsSupplementBackButton = true
Just in case someone is facing this issue with a custom back button and the above fixes did not work, here is a similar issue I faced with a different solution.
I had a customized back button with text that was disappearing while the arrow could be seen UINavigationController custom back button disappears from NavigationBar
So if anyone is facing a similar situation with disappearing back button text on a customized back button, here is my scenario and fix.
I customized my back button inside a custom NavigationController class as follows:
private func customizeBackButton() {
let backImage = UIImage(named: "BackButton")?.withRenderingMode(.alwaysOriginal)
navigationBar.backIndicatorImage = backImage
navigationBar.backIndicatorTransitionMaskImage = backImage
UIBarButtonItem.appearance().setTitleTextAttributes([
NSAttributedString.Key.foregroundColor: UIColor.panoStoryYellow,
NSAttributedString.Key.font: UIFont(name: "Montserrat-SemiBold", size: 15)!
], for: .normal)
}
This gave me:
Now when I tapped on the back button text, the text disappeared:
I made sure that I followed all the above answers such as setting titles making sure the tint color is valid etc. however this did not work.
In my case, I needed to set attributes even for the highlighted state of the back button as follows:
UIBarButtonItem.appearance().setTitleTextAttributes([
NSAttributedString.Key.foregroundColor: UIColor.panoStoryYellow,
NSAttributedString.Key.font: UIFont(name: "Montserrat-SemiBold", size: 15)!
], for: .highlighted)
After this, the back button text never disappeared
Related
Since iOS15 the QLPreviewController added some additional BarbuttonItems on the top-right side when I'm previewing a PDF-file. It added a search-button and a draw-button (the one where you can draw lines on it). It's actually pretty cool that they added it, but the Share-button is now missing, since it doesn't fit there anymore.
At least on my iPhone, because on my iPad there's enough space for three of them.
Now normally, they show the barbuttonitems that don't fit on an additional navigation bar at the bottom, but in my App the whole navigationbar at the bottom doesn't show up at all. However, it does show up if I tap it once in the middle--which makes everything but the document disappear--and then tap the middle again. Then the bottom navigationbar suddenly shows up as well, including a perfectly working Share-button.
Screenshot of the issue:
I found out that my problem was the UITabbarController at the bottom. Once I tried the functionality to hide the tabbar on push, the bottom navigationbar with the Share-button is immediately shown. It's still a bug and I'll file one at Apple, but the current solution is quite okay.
Here's the code:
let vc = OverviewsQuickLookViewController()
vc.dataSource = self
vc.hidesBottomBarWhenPushed = true
self.navigationController?.pushViewController(vc, animated: true)
I hope this might help someone!
Screenshot of the solution:
I have a strange visual bug in my app that only applies to iOS 13 running from an Xcode 11 build. I have a table view embedded in a Navigation Controller with the default tint color set to my app's primary orange color. On iOS12, when you cancel the search action, you are presented with a back button that follows the global nav controller tint of primary orange. This is the expected behavior. Image shown below:
However, this same code in iOS13 produces a system default BLUE back arrow, as shown below:
I have tried EVERYTHING to try and override that blue back button, including creating a custom Bar Button Item with a custom action, but that is way too messy and I want to just simply override the tint color. I've tried the obvious searchController.searchBar.tintColor = UIColor(named:"Primary") where searchController is my UISearchController, and I have tried to override the self.navigationController tint color. I've tried accessing the SearchBar natively, like this: UISearchBar.appearance().tintColor = UIColor(named:"Primary"), but still no luck. I've tried everything else I can think of in the IB, but I can not figure out how to reach this back button's tint color. Can anybody help?
The only way I found so far to get this fix on iOS13.1 is to iterate through the subviews in the navigation bar and manually modified the tintColor.
None of the new UINavigationBarAppearance methods looks like they fix the problem. If you modified the backButtonAppearance in UINavigationBarAppearance I have been able to fix the title in back button but I haven't found a way to fix the image (<).
try this
override func viewWillAppear(_ animated: Bool) {
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
self.navigationItem.backBarButtonItem?.tintColor = .blue
}
In iOS 13 there are few new appearance types for the navigation bar. When you want to customize navigation bar which associated with a large title or any kind of scroll view just setup appearance parameters for .scrollEdgeAppearance
if #available(iOS 13.0, *) {
let standartAppearence = UINavigationBarAppearance()
standartAppearence.configureWithDefaultBackground()
// Your configuration
UINavigationBar.appearance().scrollEdgeAppearance = standartAppearence
}
It turns out that this was an XCode/Swift bug only affecting iOS 13.1. It should not be something that you have to account for in code, since only a very small portion of the user base is still on 13.1.
So in my iOS app I have a menu designed like this:
The Images are created with the following code:
cell.imageCell?.image = menuItems[indexPath.row].image
cell.imageCell.image = cell.imageCell.image?.withRenderingMode(.alwaysTemplate)
cell.imageCell.tintColor = MenuTableViewController.fontColor
cell.imageCell.backgroundColor = UIColor.clear
This code is placed in the tableview cellForRowAt function. Now all the different viewcontrollers(HomeViewController, InfoViewController etc...) have no access at all to the menu controller and thus are not able to change the color of the image and nowhere else am I changing the color of these images. Now when I press one of the tabs that don't use any Alerts or modal views like home or info, the images stay perfectly fine, however when I press on Weather or excursions which download a json file with URLSession dataTask and display an alert telling to please wait, the images turn grey like the following:
I'm not sure how this is even possible that one viewcontroller can change another viewcontrollers subviews.
Thanks in advance
-Jorge
Perhaps what you see is a dimmed presentation of your icons. Don't use image templates or set tintAdjustmentMode to normal to stop fading icons. Usually that happens if you display alert or modal controller.
It looks like its the default UITableViewCell click style.
Try to set the style to none,
as answered here: How can I disable the UITableView selection highlighting?
Swift:
cell.selectionStyle = UITableViewCellSelectionStyle.none
I have a problem with some borderless NSButtons in a view, on a transparent popover. When the popover is first opened, the buttons look exactly as they should, but when the popover (or the view inside it) gains focus, the background becomes transparent.
The first time it is opened, it looks like this (As it should):
But when the popover gains focus, the buttons end up like this:
, where the background is transparent and the content beneath the popover is visible.
I already tried the following, which I found scattered around the web:
optionsButton.setButtonType(.MomentaryChangeButton)
optionsButton.cell?.showsFirstResponder = false
let bColor = NSColor(red: 230.0/255.0, green: 230.0/255.0, blue: 230.0/255.0, alpha: 1.0)
(optionsButton.cell as! NSButtonCell).backgroundColor = bColor
optionsButton.layer?.backgroundColor = bColor.CGColor
(optionsButton.cell as! NSButtonCell).showsStateBy = .PushInCellMask
(optionsButton.cell as! NSButtonCell).highlightsBy = .ContentsCellMask
optionsButton is, of course, the one on the right. I tried only using some of the code above, but every variation of this doesn't seem to fix it, unfortunately!
Does anyone have any idea on how to avoid this? And does someone know why the trash-button doesn't have the same problem?
Thanks in advance!
The following is tested for NSTextField, but should work for buttons as well.
Set the appearance property of the NSButton to NSAppearanceNameAqua. Because if the button doesn't try to do some weird vibrancy effect, he can't mess things up. The labels still look the same and the strange effect is gone.
My words in code:
self.button.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
Updated: SWIFT 4
The following is tested for NSButton:
NameofButton.appearance = NSAppearance(named: NSAppearance.Name.aqua)
I am trying to replace the image displayed in my right navigation bar button when it is tapped.
At the moment what seems to be happening is that it is not replacing the button, but trying to set it while the old one still exists. This leads to a strange effect as you can see:
It's a compass image, so there should only be one circle, but as you can see three are appearing.
This is my code:
let backImg: UIImage = UIImage(named: "Compass.png")!
navButton.setBackgroundImage(backImg, forState: .Normal, barMetrics: .Default)
Is there a way to remove the existing one and replace it with the new one?
Thanks.
It sounds like perhaps you are setting the UIBarButtonItem's backgroundImage when what you really want to set is its image. Thus you end up seeing both of them.