Is it possible to remove UISearchBar's tint image? - iphone

i have to hide searchbar tint.
i write foll0wing code
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 15, 270, 15)];
searchBar.delegate = self;
searchBar.barStyle = UISegmentedControlStylePlain;
searchBar.placeholder =#"search";
searchBar.tintColor=[UIColor clearColor];
[imageview addSubview:searchBar];
here search bar add on imageview. i want to hide tint side but bydeaflt it comes .i also chage the color to tint color but it not work.is anybody have idea of removing or hide tint on searchbar .Thanks

Hope this helps.
[searchBar setBackgroundImage:[UIImage new]];
Will also work in iOS 7.1

I have used this code. It completely removed the tint around the search text bar.
for (id v in [self.search subviews]) {
if (![v isKindOfClass:NSClassFromString(#"UISearchBarTextField")]) {
[v setAlpha:0.0f];
[v setHidden:YES];
}
else {
[v setBackgroundColor:[UIColor clearColor]];
}
}

Here's how I customized the UISearchBar
if ([[[searchBar subviews] objectAtIndex:0] isKindOfClass:[UIImageView class]]){
[[[searchBar subviews] objectAtIndex:0] removeFromSuperview];
}
This removes the background bar style.
You can then add any custom subview you want.

Try this
[searchBar setTranslucent:YES];
Also, don't set the tintColor when using translucent

Related

How to implement UISearchBar with no border

I am trying to add a UISearchBar without the border around it, but it's simply not working.
This is what I have:
On the XIB file, I added UISearchBar. Style = Black Transparent. Tint = Default. None of the options (bookmarks, cancel button, scope bar, etc) are selected. Background = Default. Drawing = opaque (basically the default setting of the UISearchBar).
I have a property for UISearchBar - searchBar.
In the implementation file, when the view loads, I have:
[[self.searchBar.subviews objectAtIndex:0] removeFromSuperview];
But for whatever reason, the background (the dark border around the box) is simply not going.
I tried [[self.searchBar.subviews objectAtIndex:0] setAlpha:0], but that's not working at all either.
Any help please?
This worked for me
for (UIView * view in [[[self.searchBar subviews] objectAtIndex:0] subviews])
{
if (![view isKindOfClass:[UITextField class]])
{
view .alpha = 0;
}
}
Here is the code .....
for (id img in searchBar.subviews)
{
if ([img isKindOfClass:NSClassFromString(#"UISearchBarBackground")])
{
[img removeFromSuperview];
}
}
happy coding :)
How about:
[self.searchBar setOpaque:NO];
[[_searchBar.subviews objectAtIndex:0] removeFromSuperview];
_searchBar.backgroundColor = [UIColor clearColor];
Hope this work for you, its working for me.
this work only in static UISearchBar, not if you want to show search CancelButton, this problem occur in devices having ios above 5.0.
For that you have to change/set BackgroundView of UiSearchBar.
Try This
for (UIView * view in [mySearchBar subviews]) {
if (![view isKindOfClass:[UITextField class]]) {
view .alpha = 0;
}
}
For those of you using 8.0 and above, the best solution is to simply use the UIAppearance protocol, by doing the following:
[[UISearchBar appearance] setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
You can also do it on one specific instance with:
[mySearchBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
if someone has same problem as I (see picture) code above could fix
[self.tableView setContentInset:UIEdgeInsetsMake(-1, 0, 0, 0)];

How to change color of Search Bar?

I've implemented a Search Bar and I want to change color of Search Bar. How can I do that?
I've tried with:
self.mySearchBar.backgroundColor = [UIColor redColor];
but with no success.
UPDATE (Solved):
I had to remove the default background color before I defined background color with the following code.
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
... so code would be next:
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
self.mySearchBar.backgroundColor = [UIColor redColor];
Try:
self.mySearchBar.barTintColor = [UIColor redColor];
self.mySearchBar.backgroundColor = [UIColor redColor];
won't do anything,
but
self.mySearchBar.tintColor = [UIColor redColor];
will!
self.mySearchBar.backgroundVolor = [UIColor redColor];
"Volor" or "Color
self.mySearchBar.backgroundColor = [UIColor redColor];
Also if you want to tint it:
According to the documentation : https://developer.apple.com/iphone/library/documentation/UIKit/Reference/UISearchBar_Class/Reference/Reference.html, there is a tintColor property on the UISearchBar class.
In the TableSearch example: https://developer.apple.com/library/ios/#samplecode/TableSearch/ the search bar is defined and loaded in the MainView.xib. If you want to change its tintColor or style, just do it in the xib and it will be loaded into the application.
BUT THE ONLY REAL WAY to change background color is to override it, look at the answer from the following question
UISearchBar clear background color or set background image [iphone sdk]
I'm not sure if it has changed since iOS7, but it seems that the search bar in the search display controller requires an extra loop to properly remove the UISearchBarBackground view.
I created a recursive method to properly clean the search bar.
- (void) removeUISearchBarBackgroundInViewHierarchy:(UIView *)view
{
for (UIView *subview in [view subviews]) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break; //To avoid an extra loop as there is only one UISearchBarBackground
} else {
[self removeUISearchBarBackgroundInViewHierarchy:subview];
}
}
}
You can simply send your search bar to the method and change the color afterward, a bit like the suggested answers above.
[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
self.searchDisplayController.searchBar.backgroundColor = yourUIColor;
I had to set UISearchBar's searchBarStyle to .default, otherwise nothing works.
searchBar.barTintColor = UIColor.redColor()
Try this code it works fine for me.
for( UIView* v in [parent subviews] ) {
if( [v isKindOfClass:[UISearchBar class]] ) {
[(UISearchBar*)v setTintColor:[UIColor blackColor]];
}
If you have issues with top and bottom lines try to remove the UISearchBarBackground:
self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 50)];
for (UIView *subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
for (UIView *subsubview in subview.subviews) {
if ([subsubview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subsubview removeFromSuperview];
break;
}
}
}
self.searchBar.barTintColor = [UIColor redColor];
self.searchBar.backgroundColor = [UIColor redColor];
Depends what exactly are you going to change
searchBar.barTintColor
searchBar.tintColor
Other items you are able customise thought some extra code

how to set background color as a clear color of searchbar

I want to make searchbar's background as a clear or looklike navigationbar's color
currently showing
how to make the backgroung clear of serach bar?
Beacause UI SearchBar has got its own background view, which is of black color, if we remove that view then UISearchbar's background will become clear :
for (UIView *subview in mySearchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
break;
}
}
//Search bar(using background image)
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(568, 30, 200, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"blue.png"]];
iview.frame = CGRectMake(0, 0, 200, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];
OR(using color)
//Search bar
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(568, 30, 200, 44)];
[[[bar subviews] objectAtIndex:0] setAlpha:0.0];
bar.tintColor = [UIColor colorWithRed:.376f green:.386f blue:.452f alpha:1.0];
bar.clipsToBounds = YES;
[self.view addSubview:bar];
[bar release];
Set the background image for the UISearchBar as follows.
[searchBar setBackgroundImage:[UIImage new]];
Now the UISearchBar background color will disappear. Will also work in iOS 7.1
For Clear the background color (If you want images set then use comment code)
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")])
{
// if You want set iamge then use comment code
/* UIView *backgroundView = [[UIView alloc] initWithFrame:subview.frame];
bg.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"searchBar"]];
[self.searchBar insertSubview:backgroundView aboveSubview:subview];*/
[subview removeFromSuperview];
}
}
For clearing search bar's background view :
[[[self.searchBar subviews] objectAtIndex:0] setHidden:YES];
for (id subview in self.searchBar.subviews) {
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
[subview removeFromSuperview];
}
}
I found in iOS8 that this could worked better for reducing a UISearchBar to just a text field. This will allow you to get rid of the background color.
for (UIView *subView in self.searchBar.subviews) {
for (UIView *secondLevelSubview in subView.subviews) {
if (![secondLevelSubview isKindOfClass:NSClassFromString(#"UISearchBarTextField")]) {
[secondLevelSubview removeFromSuperview];
}
}
}
Try with this line :
[[ [searchBar subviews] objectAtIndex:0] removeFromSuperview];
[[ [searchBar subviews] objectAtIndex:0] setBackgroundColor:[UIColor yellowColor]];
Surely help you out.

Is it possible to change the border color of a UISearchDisplayController's search bar?

I have a UISearchBar added as my table header with the following code.
searchBar = [[UISearchBar alloc] initWithFrame:self.tableView.bounds];
searchBar.tintColor = [UIColor colorWithWhite:185.0/255 alpha:1.0];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
Then I set my UISearchDisplayController up as follows.
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
[searchDisplayController setDelegate:self];
[searchDisplayController setSearchResultsDataSource:self];
Everything functions as I would like except that the UISearchDisplayController has added a blue(ish) border above the search bar — this bar does not recognise the tintColor I have set on the search bar.
Is it possible to change the color of this bar? It is obviously not absolutely crucial but that line is going to bug me forever if it stays blue like that!
zoomed in on UISearchBar http://nikonizer.yfrog.com/Himg256/scaled.php?tn=0&server=256&filename=4y9.png&xsize=640&ysize=640
The border doesn't seem to change very well with the Tint color, so my designer insisted that we change it. It's as simple as adding a 1px view to the bottom of your search bar:
Now in the viewDidLoad, I create a 1px view and position it at the very bottom of our search bar.
#define SEARCHBAR_BORDER_TAG 1337
- (void) viewDidLoad{
// Set a custom border on the bottom of the search bar, so it's not so harsh
UISearchBar *searchBar = self.searchDisplayController.searchBar;
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0,searchBar.frame.size.height-1,searchBar.frame.size.width, 1)];
[bottomBorder setBackgroundColor:[UIColor colorWithWhite:200.0f/255.f alpha:1.0f]];
[bottomBorder setOpaque:YES];
[bottomBorder setTag:SEARCHBAR_BORDER_TAG];
[searchBar addSubview:bottomBorder];
[bottomBorder release];
}
Now, I also transition the tint color back to default when the user is actually searching, because tinting the search bar also tints the cancel button color to an ugly color. If you do something similar, the code below will hide/show your border for each state:
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
[controller.searchBar setTintColor:nil];
// Hide our custom border
[[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:YES];
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller{
[controller.searchBar setTintColor:[UIColor colorWithRed:238.0f/255.0f green:245.0f/255.0f blue:248.0f/255.0f alpha:1.0f]];
//Show our custom border again
[[controller.searchBar viewWithTag:SEARCHBAR_BORDER_TAG] setHidden:NO];
}
searchBar.searchBarStyle = UISearchBarStyleMinimal;
Try this:
searchBar.clipsToBounds = YES;
Original question link

UIWebView underside

Is there a way to change the color of the gray underside of the UIWebView that's seen when the page is overscrolled?
Just set the backgroundColor property.
Below I mentioned swift 3 syntax, currently instead of Color, Xcode is providing color plate for mentioning color
webview.backgroundColor = Color.white
[self.webView setBackgroundColor:[UIColor clearColor]];
for(UIView* subview in [self.webView1 subviews]){
if([subview respondsToSelector:#selector(setBackgroundColor:)]){
[subview setBackgroundColor:[UIColor clearColor]];
}
for(UIView* imageView in [subview subviews]){
if([imageView isKindOfClass:[UIImageView class]]){
imageView.hidden = YES;
}
}
}