0

I've to make my navigation bar transparent, I tried with this code :

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

But my navigation bar become white, I don't understand the reason! Can someone help to solve this problem?

Patrick
  • 12,336
  • 15
  • 73
  • 115
Leonardo
  • 218
  • 4
  • 17

1 Answers1

1

You are doing right way to make transparent UINavigationBar but seem like you have a wrong constraint. Make sure you top constraint of your scrollView is equal to Superview.Top.

enter image description here

If your top constraint of your scrollView is equal to Safe Area.Top, of course your ScrollView won't scroll below UINavigationBar.

enter image description here

trungduc
  • 11,926
  • 4
  • 31
  • 55
  • I have tried it before writing answer and it works normally. Is there anything else with your code? – trungduc Nov 02 '17 at 15:31
  • i don't know, also the status bar become white... i made a lot of apps but but this problem is new for me -.- Surely there is something else but i don't know where... – Leonardo Nov 02 '17 at 15:44
  • Did you try to put anything below navigation bar? Status bar or navigation bar? – trungduc Nov 02 '17 at 15:45
  • maybe this can help you to help me haha : i can't also hide the status bar... i set it hidden from storyboard and programmatically but nothing... – Leonardo Nov 02 '17 at 15:55
  • Opps ;) . @Leonardo can i get a minimal debug repo? It will be easier for us. – trungduc Nov 02 '17 at 15:59
  • sorry for the question, but how? – Leonardo Nov 02 '17 at 16:01
  • @Leonardo you can create and up load it to Github and give me the link ;) – trungduc Nov 02 '17 at 16:02
  • sorry but i really can't, this is app of an important company and i can't give it's source code, unfortunately :( – Leonardo Nov 02 '17 at 16:04
  • @Leonardo, no. I mean a new project and you just need to write something like issue in your question. And after that i will check it. – trungduc Nov 02 '17 at 16:05
  • oh sorry, but the problem is that i made a trasparent navigationbar a lot of times but in this project there something strange -.- So i don't know how to recreate the issue, i'm working on this project few some months, before another developer worked on it... it's driving me crazy. – Leonardo Nov 02 '17 at 16:12
  • no, also setting the top constraint equal to superview.top the navigation is still white -.- And if i go back from this ViewController the NavigationBar is white also in the another ViewControllers of the same Navigation. – Leonardo Nov 03 '17 at 13:44
  • @Leonardo, did you check my repo? – trungduc Nov 03 '17 at 13:49
  • i'm using xcode 8.3 for some compatibilty reasons, so i can't open your project's storyboard -.- – Leonardo Nov 03 '17 at 13:57
  • Let discuss in chat @Leonardo – trungduc Nov 03 '17 at 13:59
  • @Leonardo If you can fix it, please let me know why ;) – trungduc Nov 03 '17 at 14:18
  • Ok i found the solution, you helped me so much : i've corrected the constraints how you indicated me then i checked the three checkbox : https://i.stack.imgur.com/yyKl1.png – Leonardo Nov 03 '17 at 14:34
  • @Leonardo please let me know, you can comment here or send through discussion. – trungduc Nov 03 '17 at 14:35
  • Congratulation @Leonardo ;) – trungduc Nov 03 '17 at 14:37
  • i set top constraint to superView but not working messagesCollectionView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true – famfamfam Mar 30 '21 at 07:04