faded, pale background color in UITabBar.background - ios

guys, I am trying to customize UITabBar, but problem is that when I set up simple green background color in UITabBar.background, result is insufficient. Like something lies on background. Here it is look like:
UITabBarController is created in storyboard, but background color I set up in code. Here is appDelegate:
TabBarController* bc=(TabBarController*)self.window.rootViewController;
bc.tabBar.backgroundColor=[UIColor greenColor];
If I set up pictures on background and on items - they just almost invisible. I've tried playing with tint colors on the right bar in storyboard, but all was useless.

I had a similar issue when programmatically creating the UITabBarController background color in iOS 8. The problem was I was using backgroundColor when I should have been be using barTintColor. Try this.
TabBarController* bc=(TabBarController*)self.window.rootViewController;
bc.tabBar.barTintColor=[UIColor greenColor];
Let me know if that works for you.

You need to set the transparency of the tabBar:
Swift :
self.tabBar.translucent = false
Objective C :
[[self tabBar] setTranslucent:NO]

The same in Swift, iOS 9.
self.tabBarController?.tabBar.barTintColor = UIColor(red: 254/255.0, green: 200/255.0, blue: 93/255.0, alpha: 1.00)

Related

RGB Color, wrong color

I am currently working on an iOS Application in Swift 3 and wanted to change the color of my NavigationBar
with the following code:
self.navigationController?.navigationBar.barTintColor = UIColor.init(red: 53.0/255.0, green: 70.0/255.0, blue: 90.0/255.0, alpha: 1.0)
This code works quite fine but there's one problem. The color I entered in RGB format is displayed wrong.
Should be like this color:
But looks like this (left: is current Color () right: as already said should look like):
Set navigationController?.navigationBar.isTranslucent = false.
You can also achieve this by unchecking Translucent from storyboard.
Change navigation bar to Opaque instead of Translucent.
Swift
self.navigationController?.navigationBar.isTranslucent = true
Objective-C
[[UINavigationBar appearance] setTranslucent:YES];
Please find in image.
And if you are setting navigations background color then change
navigation background color instead of tint color.

Change tab bar item selected color in a storyboard

I want to change my tab bar items to be pink when selected instead of the default blue.
How can i accomplish this using the storyboard editor in Xcode 6?
Here are my current setting which are not working, the blue background works but the pink doesnt work:
Add Runtime Color attribute named "tintColor" from StoryBoard. This is working(for Xcode 8 and above).
if you want unselected color.. you can add unselectedItemTintColor too.
This elegant solution works great on SWIFT 3.0, SWIFT 4.2 and SWIFT 5.1:
On the Storyboard:
Select your Tab Bar
Set a Runtime Attibute called tintColor for the desired color of the Selected Icon on the tab bar
Set a Runtime Attibute called unselectedItemTintColor for the desired color of the Unselected Icon on the tab bar
Edit: Working with Xcode 8/10, for iOS 10/12 and above.
In Swift, using xcode 7 (and later), you can add the following to your AppDelegate.swift file:
UITabBar.appearance().tintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
This is the what the complete method looks like:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// I added this line
UITabBar.appearance().tintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255.0, alpha: 1.0)
return true
}
In the example above my item will be white. The "/255.0" is needed because it expects a value from 0 to 1. For white, I could have just used 1. But for other color you'll probably be using RGB values.
On Xcode8 I have changed the ImageTint from the storyboard and it works well.
The result:
Swift 3 | Xcode 10
If you want to make all tab bar items the same color (selected & unselected)...
Step 1
Make sure your image assets are setup to Render As = Template Image. This allows them to inherit color.
Step 2
Use the storyboard editor to change your tab bar settings as follows:
Set Tab Bar: Image Tint to the color you want the selected icon to inherit.
Set Tab Bar: Bar Tint to the color you want the tab bar to be.
Set View: Tint to the color you want to see in the storyboard editor, this doesn't affect the icon color when your app is run.
Step 3
Steps 1 & 2 will change the color for the selected icon. If you still want to change the color of the unselected items, you need to do it in code. I haven't found a way to do it via the storyboard editor.
Create a custom tab bar controller class...
// TabBarController.swift
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
// make unselected icons white
self.tabBar.unselectedItemTintColor = UIColor.white
}
}
... and assign the custom class to your tab bar scene controller.
If you figure out how to change the unselected icon color via the storyboard editor please let me know. Thanks!
This best way is to change Image Tint in storyboard
put this code in the viewDidLoad of the view controller that you want to change the color of
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
You can also set selected image bar tint color by key path:
Hope this will help you!! Thanks
XCode 8.2, iOS 10, Swift 3: now there's an unselectedItemTintColor attribute for tabBar:
self.tabBar.unselectedItemTintColor = UIColor(red: 0/255.0, green: 200/255.0, blue: 0/255.0, alpha: 1.0)
You can change colors UITabBarItem by storyboard but if you want to change colors by code it's very easy:
// Use this for change color of selected bar
[[UITabBar appearance] setTintColor:[UIColor blueColor]];
// This for change unselected bar (iOS 10)
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor yellowColor]];
// And this line for change color of all tabbar
[[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
Somehow we are not able to change the Tab Bar selected item Tint color using storyboard alone, hence I added below code in my ViewDidLoad, hope this helps.
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
Add this code in your app delegate -did_finish_launching_with_options function
UITabBar.appearance().tintColor = UIColor( red: CGFloat(255/255.0), green: CGFloat(99/255.0), blue: CGFloat(95/255.0), alpha: CGFloat(1.0) )
put the RGB of the required color
Image Tint from storyboard worked for me.
This is the solution in Swift 3 that works in iOS 10:
Firstly, you create your own tab bar controller subclass and add it to your tab controller in your storyboard. In the viewDidLoad() method you can then customize the tab bar. It should be stated here that the tintColor attribute of the tabBar represents the color of the selected item not the color of the unselected ones! In order to change the color of the unselected items, I recommend looping through each item and use the original colors of your images, so they are not rendered as grey automatically.
class CustomTabBarVC: UITabBarController
{
override func viewDidLoad()
{
super.viewDidLoad()
self.tabBar.tintColor = AppColor.normalRed
self.tabBar.barTintColor = .white
self.tabBar.isTranslucent = true
if let items = self.tabBar.items
{
for item in items
{
if let image = item.image
{
item.image = image.withRenderingMode( .alwaysOriginal )
}
}
}
}
}
The only downside with this approach is that your item images must already have the desired color you aim for.
You can subclass the UITabBarController, and replace the one with it in the storyboard.
In your viewDidLoad implementation of subclass call this:
[self.tabBar setTintColor:[UIColor greenColor]];

Can't change search bar tint color to be transparent in iOS 8

Upgraded from Xcode 5 to 6 and now my search bar tint is black.
Tried to change it through storyboard right pane > "Bar Tint" to clear color, but it's still black.
Also tried programmatically:
[self.searchBar setTintColor:[UIColor clearColor]];
Still black :(
Any ideas?
The tintColor property on search bars, much like UINavigationBar, changes the color of the buttons, as well as changes the color of the blinking cursor, not the actual search bar background. What you want to use is the barTintColor property.
searchbar.barTintColor = [UIColor orangeColor];
searchbar.tintColor = [UIColor greenColor];
Produces the following ugly, yet informative, result:
If you want to have a completely transparent search bar, you need to set the background image as well:
searchbar.barTintColor = [UIColor clearColor];
searchbar.backgroundImage = [UIImage new];
EDIT: I would strongly advise against traversing and modifying the subviews of any UIKit object, as has been proposed in other answers. From Apple's documentation:
For complex views declared in UIKit and other system frameworks, any
subviews of the view are generally considered private and subject to
change at any time. Therefore, you should not attempt to retrieve or
modify subviews for these types of system-supplied views. If you do,
your code may break during a future system update.
https://developer.apple.com/documentation/uikit/uiview/1622614-subviews
I got to change it on iOS 9 using Swift 2.0 this way:
let image = UIImage()
searchBar.setBackgroundImage(image, forBarPosition: .Any, barMetrics: .Default)
searchBar.scopeBarBackgroundImage = image
On Swift 3:
Setting up the background of the searchBar to an empty image:
searchBar.setBackgroundImage(image, for: .any, barMetrics: .default)
searchBar.scopeBarBackgroundImage = image
for programmatically change search bar tint color :
if let textfield = searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = #colorLiteral(red: 0.3921568627, green: 0.3921568627, blue: 0.3921568627, alpha: 1)
textfield.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
}
for storyboard :
I've been seeing this problem as well on iOS8 / XCode 6. I did not get the search bar translucent. searchbar.barTintColor or searchbar.tintColor setting to clear color did not help or shows a black searchbar.
The only workaround i found was to set a translucent background png image (alpha=0.0) and setting searchbar.barTintColor to clear color.

UISearchBar and/or UISearchDisplayController color

UPDATE: Thanks for all the answers. I would like to add that the search bar used is actually a UISearchBar embedded as part of UISearchDisplayController that is set to the a UITableView's header.
I've created a sample project exhibiting this behavior here: https://dl.dropboxusercontent.com/u/3497087/TestSearchDisplayController.zip. I tried setting the barTintColor to blue and black. The most obvious thing is that when setting to black, I get a grayish bar.
I appreciate all answers and ideas, thank you.
I am working on skinning the app that I'm currently working on, and I seem to hit a roadblock with UISearchBar and/or UISearchDisplayController bar color.
The first issue I have revolves around setting the barTintColor for UISearchBar that is attached as a tableview header. I've set it to blackColor in Interface Builder. However, when the app runs, the color doesn't seem to be black, but some sort of gray, with an ugly white line above! I've tried setting this thru code, but that doesn't seem to help too. See screenshots below.
My second question revolves around UISearchDisplayController. I wanted black color when the search display controller takes over the top of the screen. I've tried setting the color code, but the only color that it won't take is, again, black color!
[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:#"black"]];
check out your sample project
You can try with this:
_searchBar.barTintColor = [UIColor blackColor]; // change the barColor
_searchBar.tintColor = [UIColor whiteColor]; // change the title color
It's as simple as setting searchBar.barTintColor to the color you want. No need for images. searchBar.tintColor changes the color of the Cancel button.
I just add a helper function to set everything, including the cancel button color (tint.color). This called in ViewDidLoad:
//Set the searchbar settings, delegates
func setSearchBar() {
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.searchBar.placeholder = "Enter Search Text"
searchController.searchBar.barTintColor = UIColor(red: 72/255, green: 100/255, blue: 156/255, alpha: 1)
searchController.searchBar.tintColor = UIColor.white
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
}
You can also set own color for searchbar color (barTintColor). This works in Xcode 8 and Swift 3.
For your first question, I had the same issue few months ago. Have a look at: iOS7, backgroundImage for UISearchBar
At the end, it uses the method:
setBackgroundImage:forBarPosition:barMetrics:
Getting control of the iOS 7 search bar background color is tricky. The easiest and most reliable approach: Make a solid black image and call setBackgroundImage:forBarPosition:barMetrics:. (Getting the second and third arguments right is also tricky!) Also explicitly set the bar's translucent to NO just to be on the safe side. Do all this in code; do not rely on Interface Builder to get things right.
For Background Color of Searchbar :
For TintColor:
[self.searchDisplayController.searchBar setTintColor:[UIColor redColor]];
Hi You can try with this
_searchBar.tintColor = [UIColor blackColor];
_searchBar.backgroundColor = [UIColor clearColor];
_searchBar.backgroundImage = nil;

CollectionView background clearColor not working

I'm developing a small collectionview 'framework' to behave like a browser tab bar (think chrome) on the iPad. The code is all done, custom flow layout, reordering, and so on and is organized as so :
• TabBarCollectionViewController .h/.m/.xib contains the high logic of the collection view (delegates + datasource methods). I have the xib to configure the collectionView settings and set the custom flow layout (I could do this programmatically, but oh well it's easier that way).
• CustomFlowLayout .h/.m (subclass of flow layout)
• TabBarCell .h/.m/.xib (subclass of collectionviewcell)
Then I'm adding the TabBarCVC as a childViewController on my main viewController (this viewController has many childViewController and subviews) and then as a subview.
At this point all is working fiiiiine.
Now the problem, it's so stupid i can't believe i haven't found a way to do this, the backgroundColor of the collectionView is not settable to clearColor. I can put it in gray or whatever color, but that it doesn't support transparency. The cell background color is also clear and does work.
I need the collectionView to be transparent to show the texture on the main view behind. Any insight would be much appreciated, or perhaps i'll fill my first radar to apple.
If i can't find any solution i'll just add the 'screenshot' of the texture supposed to be behind the collectionView and add it as a imageView in the collectionView's backgroundView.
In my case I had the background color in the storyboard set to Default. This caused it to have a black background. Changing it to Clear Color worked.
Try setting the color to clear and the background view to an empty view like so...
self.collectionView.backgroundColor = [UIColor clearColor];
self.collectionView.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
Ok so i'm feeling pretty stupid now. I left an empty UIView behind, acting as a container for the collectionView for a test. I simply forgot to remove it, all is working fine with a nice clearColor now...
Watch out when setting UICollectionViews Background Color in Storyboard:
The initially selected value Default is Black (counterintuitively).
You have to explicitly select Clear Color for the View to be transparent.
Also note that the Preview in Storyboard immediately changes when this is done 'right'...
The easiest solution is just pick anything color in color picker to change collectionview background then turn the opacity to 0%.
I solved it using in Swift 3:
collectionViewVideo.backgroundColor = UIColor.clear.withAlphaComponent(0)
Fogmeister's answer worked great. Adapted to Swift 3, it would be:
self.collectionView.backgroundColors = [NSColor.clear]
self.collectionView.backgroundView = NSView.init(frame: CGRect.zero)
Swift 4.0 from Fogmeister's answer
self.collectionView.backgroundColor = UIColor.clear
self.collectionView.backgroundView = UIView.init(frame: CGRect.zero)
To have a nice semi-transparent white background use:
collectionView.backgroundColor = UIColor(displayP3Red: 1.0, green: 1.0, blue: 1.0, alpha: 0.35)
In swift this work with me:
self.collectionView.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 0.0)
What is did to fix it
From Storyboard set collection view background colour as clear colour
then set main view colour to any colour you want , (I set to white.)

Resources