Change Background Color Status Bar iOS - swift

So, I'm trying to make this:
i tried using UIView in back of Status bar and set the color to orange, but when running, The UIView displayed right under the status bar, so it's still White
i'm trying many solution in the internet but none of them work. Yes it works but when i move to other view controller and back again, The color dissapeared. What should I do? i'm using swift

UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().clipsToBounds = true
let statusBar: UIView = UIApplication.shared.value(forKey: "statusBar") as! UIView
statusBar.backgroundColor = UIColor.orange
Try using this code in your appDelegate's method application didFinishLaunchingWithOptions

Related

it is impossible to hide status background when i'm using UITabbar in Swift

I'm using UITab bar. In my UITabbar have 4 items and each of tabbar have navigation controller.
i want to put gradient color in the status background of view controller in 1-3 items but in view controller 4 i want it to have a status clear background.
my problem is when i go to tab 1-3 and then go to tab 4 the status background color will change according to the of tab 1-3. But I want the status background color of tab 4 is transparent.
the code that I use to change color of status background in tab 1-3
if let status = UIApplication.shared.value(forKey: "statusBar") as? UIView {
status.setGradientBackground(colorOne: Colors.carmine, colorTwo: Colors.cherryRed, colorThree: Colors.cherryRedTwo)
}
I have tried to hide status bar in Tab 4 by this method
1.change View controller-based status bar appearance to YES
2.put
setNeedsStatusBarAppearanceUpdate()
in viewdidload
3.put
override var prefersStatusBarHidden: Bool {
return true
}
in viewdidappear but still not work background of status bar is not hidding and the status background color still change according to the of tab 1-3.
it have one method that work by using this code
UIApplication.shared.isStatusBarHidden = true
and put it in every view controller
but it have warning like this
Setter for 'isStatusBarHidden' was deprecated in iOS 9.0: Use -[UIViewController prefersStatusBarHidden]
I want to know the correct way to change color of the status bar in UITab Thank you.
Ok, if I understand what you want correctly, you want to make your tab 4 to have a clear status bar, here's what you can try if your main view in tab 4, has subviews. Once you change your main view color, the status bar color changes also :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
if let lastTab = tabBarController?.children[3] {
lastTab.view.backgroundColor = UIColor.white // status bar will be clear
}
}

Erase borders between navigation bar and searchBar swift 4

I am setting both the navigation bar and the search bar to a custom UIColor (which I call categoryColor in my code). When I do that, I still see an upper grayish line between nav bar and search bar. I have already set the searchBar border color to be the same as the others, but that gray line still exists. Does anyone know how to get rid of it?
Here is my code:
override func viewWillAppear(_ animated: Bool) {
//defining the color that will be used for all the items
let categoryColor = UIColor(hexString: selectCategory?.categoryColorHex ?? UIColor.randomFlat.hexValue())
//changing navigation bar tint color
navigationController?.navigationBar.barTintColor = categoryColor
//changing searchbar tint color
searchBar.barTintColor = categoryColor
//change searchBar border's color
searchBar.layer.borderColor = categoryColor?.cgColor
searchBar.layer.borderWidth = 3
//changing title that appears at the top, after list is loaded
title = selectCategory?.listName ?? "Todoey"
}
Here is a picture of what I see when I run the simulation:
The better way for implementing search bar with nav controller would be to use searchController inside a navigationController so the searchController will have the same background as navigationController. Here’s a great tutorial about that: https://m.youtube.com/watch?v=h7caxpp3Xps
Edit:
Also if you already implemented search capabilities you can do that with searchController too. Just set navigationController.searchConroller.searchBar.delegate for class that’s responsible for handling delegate methods

Cannot get transparent Tab Bar in tvOS

I'm having a hard time getting a UITabBar with a completely transparent background on tvOS : I Always get a whitish background.
I tried the following (Setting background color clear, background image to UIImage) but nothing worked.
var appearanceTabBar = UITabBar.appearance()
appearanceTabBar.barTintColor = UIColor.clear
appearanceTabBar.shadowImage = UIImage()
appearanceTabBar.backgroundImage = UIImage()
Result is the following :
does anybody have any idea on how i can make the background completely transparent ?
Setting the color as the same purple is not a good idea as a picture may be on the background.
Thank you :)
Mickael
I was having the issue, you have to wait for the tab bar UI to be "ready". I solved it inheriting from UITabBarController and overriding viewWillAppear.
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.tabBar.backgroundImage = UIImage()
}
I guess you don't have to extend from UITabBarController, you probably can achieve the same result just overriding viewWillAppear on your main view controller.

Why I cannot make my UITabBarController blurred?

I have a UITabBar and I want to make it blurred. I wrote the following code:
import UIKit
class TabBarController:UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let blur = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = self.view.bounds
blurView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.view.layer.insertSublayer(blurView, atIndex: 0)
}
}
but somehow the last line throws error:
Cannot convert value of type 'UIVisualEffectView' to expected argument
type 'CALayer'
how can I fix that?
I changed the last line to:
self.tabBar.addSubview(blurView)
but now the whole tabbar is blurred (even with icons and they are not visible). When I changed this line to:
self.tabBar.sendSubviewToBack(blurView)
then the tabbar is visible, but not blurred. I want to achieve effect from accepted answer from here Black background on transparent UITabBar but here it is uitabbar and I'm using uitabbarcontroller... Can you help me with applying blur in my case?
You just add the blur view as a subview:
self.view.addSubview(blurView)
Since you just want to blue the tab bar and this class is a tab bar controller, you can do:
self.tabBar.addSubview(blueView)
You also need to change the frame:
blurView.frame = self.tabBar.bounds
why don't you just use the barTintColor property on your TabBarController?
self.tabBar.translucent = true
self.tabBar.barTintColor = UIColor.blackColor()
You don't even need to subclass UITabBarController. You can call this on any UIViewController.
self.tabBarController?.tabBar.translucent = true
self.tabBarController?.tabBar.barTintColor = UIColor.blackColor()
If I understood correctly from the following comment that you posted, you want to change the UITabBar to be black in colour but still blurred.
And yes, I noticed that the UITabBarController is blurred by default, but I would like to make it blurred with specific style (.Dark).
Doing this since iOS 7 has actually become quite easy. Simply change the barStyle of your UITabBar to .black. Put the following code in your UIViewController's viewDidLoad method (note that UITabBar is translucent by default, so you don't need to specify that again).
tabBarController?.tabBar.barStyle = .black
If you want to set it back to the regular, white barStyle, change it back to .default.
tabBarController?.tabBar.barStyle = .default
You may even do this from within Interface Builder by selecting the Tab Bar in your UITabBarController's hierarchy and changing its Style to Black.
I have a solution, all you need is configure your UITabBar as following:
// next code will make tabBar fully transparent
tabBar.isTranslucent = true
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage() // add this if you want remove tabBar separator
tabBar.barTintColor = .clear
tabBar.backgroundColor = .black // here is your tabBar color
tabBar.layer.backgroundColor = UIColor.clear.cgColor
If you want to add blur, do this:
let blurEffect = UIBlurEffect(style: .dark) // here you can change blur style
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame = tabBar.bounds
blurView.autoresizingMask = .flexibleWidth
tabBar.insertSubview(blurView, at: 0)
As a result:
Attach bottom constraint to the bottom of the view instead of Safe Area
It just might not be a problem with your TabBar but with tableView constraints.
Tab bar is blurred by default.

UITabBarController customisation page top bar colour swift

How do I change the colour of the top bar of the customisation page of the more view controller. Please see the linked image. Sorry I can't post image here because of my low reputation.
Screenshot Image
Edited with more info:
I have managed to change the background color using the following code. But cant change the color of the top bar.
func tabBarController(tabBarController: UITabBarController, willBeginCustomizingViewControllers viewControllers: [AnyObject]) {
var editView : UIView = tabBarController.view.subviews[1] as! UIView
editView.backgroundColor = UIColor.blackColor()
}
Basically 2 Ways you can achieve this if you are using Global Unique colour in the app for All navigation bar
Use this Solution on App Launch:
UINavigationBar.appearance().barTintColor = UIColor.redColor()
Or if you want to change the Color of More navigationcontroller only then
Use this Solution by getting the Tabbar Reference :
self.tabBarController?.moreNavigationController.navigationBar.barTintColor = UIColor.greenColor()
You can use second solution in the First viewcontroller of the Tab, because that contains your tabbar reference