Cannot get transparent Tab Bar in tvOS - swift

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.

Related

Swift how to remove uisegmentControl default black backgroundColor?

I know a lot of people asked this question, but nothing helps. My controller1 presents a new controller2 from storyboard. Controler1's background color is black. My customized segmentcontrol background color and selectedTintColor work well, but always show a black background color first. I tried every way, but not working. In storyboard and code, all no this black color. Thanks!
override func viewDidLoad() {
let bgColor = uIColor. // my customized color)
segmentControl.backgroundColor = bgColor
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
connectionSegmentControl.selectedSegmentIndex = 0
toggleSegmentTintColor()
}
private func toggleSegmentTintColor() {
// I set my customized selected tint color here, it works.
}
If you do this in viewDidAppear, its too late: the view is on the screen. The hack way to do it is in viewDidlaod or viewWillAppear. The right way to do it is to to use UIAppearance proxy on app launch to set the tint color for your object globally:
UISegmentedControl.appearance().tintColor = UIColor.clear
You can also set the tint color for the whole app by setting it on the root window, but then it affects more than just the segmented controls.

UIImagePickerController Navigation Bar Tint Color not working with iOS 13

I am presenting a modal controller which is a UIImagePickerController.
I am trying to change the UIImagePickerController navigation bars' tint colour.
Prior to iOS13 this worked fine;
imagePickerController.navigationBar.tintColor = .red
I have also tried;
imagePickerController.navigationController?.navigationBar.tintColor = .red
but still no joy.
What can I try next?
This was resolved with rmaddy's solution in the comments.
in AppDelegate implement;
func configureGlobalUI() {
UINavigationBar.appearance().tintColor = .red
}
then call in didFinishLaunchingWithOptions
This works as I require the tintColor on all navigationBar appearances.
You can just make UIView the size of the Navigation Bar and put it under navigation bar and make navigation bars color alpha=0.
I hope this helped. :)

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.

Change Background Color Status Bar iOS

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

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