How to create Transparent background for UITableView and UISearchBar - ios

In my application i added one UITableView and UISearchBar and its background by default white color. I would like to change the background of both items to clear or transparent, For that i tried to change the background colors .
tableview.tintColor=[UIColor clearColor];
srchbar.tintColor=[UIColor clearColor];
But its not affect on UI. How to do it properly?
The UI screenshot given bellow .

For TableView
[self.yourtableView setBackgroundView:nil];
[self.yourtableView setBackgroundColor:[UIColor clearColor]];
And asign clear color to cell
cell.backgroundColor = [UIColor clearColor];
And for UISearchBar
[self.yourSearchBar setBackgroundColor:[UIColor clearColor]];
[self.yourSearchBarsetBackgroundImage:[UIImage new]];
[self.yourSearchBar setTranslucent:YES];

For iOS7+, all you need to do is:
[self.searchBarHome setBackgroundColor:[UIColor clearColor]];
[self.searchBarHome setBarTintColor:[UIColor clearColor]]; //this is what you want
as written in Make UISearchBar background clear

Related

UITableView background color iOS 9

I have a UITableView that I want to set its background color to transparent. Background color for the table view and all subviews at interface builder is set to transparent. It works fine for iOS 8 & 7. but, not iOS 9. any idea?
cellForRowAtIndexPath method:
[cell setSelectedBackgroundView:[[UIView alloc] init]];
[cell.selectedBackgroundView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundColor:[UIColor clearColor]];
[cell.contentView setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:[[UIView alloc] init]];
[cell.backgroundView setBackgroundColor:[UIColor clearColor]];
Objective-c:
[self.yourTableView setBackgroundColor:[UIColor clearColor]];
Swift:
self.yourTableView.backgroundColor = .clear
XCode 7.0 bug. Not picking up from Storyboard
This happens to me even when creating an UITableView in code, and setting it as a private property of my UIViewController. However, if the UITableView is a global variable, this problem does not occur.
I suspect Apple is rooting around the ivars on my UIViewController, setting UITableView's background colors to UIColor whiteColor without asking me. I have checked, and the calls to do go through setBackgroundColor on the UITableView.

How to make UINavigationBar fully transparent or gone like this only title and UIBarButtonItem could be seen

As you can see, the UINavigationBar is fully transparent. Only the title and UIBarButtonItem is visible. And the status bar has the same colour as UITableView's background colour. Right now, I have finished to make the table view and cell has the same effect as the pic. But how to make the navigation bar and the status bar has the effect too?
Try this one
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
Try this !
[self.navigationController.navigationBar setBackgroundColor:[UIColor clearColor]];
[self.navigationController.view setBackgroundColor:[UIColor clearColor]];
[self.navigationController.navigationBar setBarTintColor:[UIColor clearColor]];

How to set UISwitch border color?

My app has:
[[UIView appearance] setTintColor:[UIColor whiteColor]];
And here is what I have when on:
and off:
I need to make UISwitch border visible like in Settings.app:
Your [[UIView appearance] setTintColor:[UIColor whiteColor]]; is interfering with the tint color of your switch. The command to set the tint color is self.mySwitch.tintColor = [UIColor grayColor]; which sets the color used to tint the outline of the switch when it is turned off.
Will you please try adding this line to your AppDelegate's didFinishLaunchingWithOptions
[[UISwitch appearance] setTintColor:[UIColor grayColor]];
This should apply the chosen Tint color on all your UISwitch controls.
Rather than using the appearance proxies you can also use:
[self.mySwitch setThumbTintColor:[UIColor blueColor]];
[self.mySwitch setOnTintColor:[UIColor redColor]];
ie. Use setOnTintColor for the background/border color.

Globally set background color of buttons, except accessory buttons in UITableView

I am using the below code to make all my buttons in an application the same color. However the accessory icon in the UITTableView row also has it. Is there a way to ignore it in the table view?
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
A UIView conforms to the UIAppearanceContainer protocol.
So you should use appearanceWhenContainedIn: to distinct buttons depending on where they are contained in.
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
[[UIButton appearanceWhenContainedIn:[UITableView class], nil] setBackgroundColor:nil];
It would be best to use the UITableViewCell subclass instead of the table view.
You can use the
[[UIButton appearanceWhenContainedIn: [UITableView class]] setBackgroundColor:[UIColor differentColor]];

Navigation bar background color - translucency is no

I would like to change the background color of the navigation bar to a solid green.
Rule: I can't mess with the AppDelegate :)
I've tried:
//It's green but it's translucent
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//It's white, first line has no effect
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
[self.navigationController.navigationBar setTranslucent:NO];
//Same result as case 1
[self.navigationController.navigationBar setAlpha:0.0f];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//Too dark
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[self.navigationController.navigationBar setBackgroundColor:[UIColor colorWithRed:77/255.0 green:255/255.0 blue:100/255.0 alpha:1.0f]];
//Only affects the back button's color:
[self.navigationController.navigationBar setTintColor:[UIColor greenColor]];
So any ideas?
Thank you, didn't see there was barTintColor and TintColor as well. Accepting earliest answer.
Use this line of code in your viewController didLoad method
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29.0f/255.0f green:149.0f/255.0f blue:174.0f/255.0f alpha:1.0f]
Use this one,
self.navigationController.navigationBar.tintColor=[UIColor colorWithRed:19.0/255.0f green:52.0/255.0f blue:36.0/255.0f alpha:1];
use barTintColor property of navigationBar
Please use following code may be this will help you.
navController.navigationBar.barTintColor = [UIColor yourcolor];

Resources