Color different in UISearchBar? - ios

Following is the code to customize the searchBar embedded in the navigationBar. I set the same tintColor for both navigationBar and searchBar. Bur it seems there is some difference in tabbar's tint color and navigation bar tint color. What could be the problem?
- (void)viewdidLoad:(BOOL)animated
{
//Change the navigation bar color
[self.navigationController.navigationBar setBarTintColor:kAppNavigationItemGrayColor];
//Create a UISearchBar
UISearchBar *topBarSearchBar = [[UISearchBar alloc] init];
[topBarSearchBar setBarTintColor:kAppNavigationItemGrayColor];
//Wrapper view to hold searchbar
UIView *searchBarWrapper = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
[topBarSearchBar setFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
[searchBarWrapper setBackgroundColor:[UIColor clearColor]];
[searchBarWrapper addSubview:self.topBarSearchBar];
[self.navigationItem setTitleView:searchBarWrapper];
self.navigationItem.hidesBackButton = YES;
}

Try this [searchBarWrapper setBackgroundColor: kAppNavigationItemGrayColor];

Try to set,
self.navigationController.navigationBar.translucent = NO;

Related

Adding UISegmentedControl in UISearchDisplayController

I want to add the UISegmentedControl below the searchBar and above the TableView of UISearchDisplayController. Currently UISearchDisplayController only shows its tableView under its SearchBar.
But i want to add a UISegmentedControl below the SearchBar so that I have SearchBar on the top, after SearchBar I have a UISegmentedControl and below that UISegmentedControl I have UITableView. Is that any way to do this using UISearchDisplayController or i have to make my own SearchDisplayController that have its own SearchBar , UISegmentedControl and TableView?
any suggestion? Thanks
Enable ShowScopeBar and add as many as segments by adding scop titles and handle them by following method
By Code
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[searchBar setShowsScopeBar:YES];
[searchBar setScopeButtonTitles:#[#"button1",#"button2"]];
[[self view] addSubview:searchBar];
By XIB
Delegate method to handle scope button action
- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope{
}
Create a view in table
UIView *viewsearch=[[UIView alloc]initWithFrame:CGRectMake(0,-10, 320,83)];
[self.tblname addSubview:viewsearch];
[self.view addGestureRecognizer:revealController.panGestureRecognizer]
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,5, 320, 40)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
searchBar.delegate=self;
[searchBar setBarTintColor:[UIColor colorWithRed:(249/255.0) green:(9/255.0) blue:(99/255.0) alpha:1]];
searchBar.tintColor = [UIColor whiteColor];
searchBar.placeholder = #"Search items e.g. jacket";
Addsearchbar view in that view.
[viewsearch addSubview:searchBar];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
Use UISegmentedControl in this searchview.
NSArray *itemArray = [NSArray arrayWithObjects: #"General", #"Near me", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(50,53, 225, 22);
segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain;
[segmentedControl addTarget:self action:#selector(MySegmentControlAction:) forControlEvents: UIControlEventValueChanged];
segmentedControl.selectedSegmentIndex = 0;
segmentedControl.tintColor = [UIColor colorWithRed:(249/255.0) green:(10/255.0) blue:(99/255.0) alpha:1];
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleBottomMargin;
[viewsearch addSubview:segmentedControl];
I find the solution for my Problem that i added the UISegmentedControl as a Header of TableView of UISearchDisplayController. In this way it just looked like that i have added a UISegmentedControl Separately under the searchBar of UISearchDisplayController.
Thank You every one who tried to help.

iOS: REMOVING programmatically added search bar from navigation bar

Scenario
In my app there is a navigation bar with a "magnifying glass" icon in the upper righthand side. When the user taps on this icon the titleView for the navigation bar will be replaced by a UISearchBar.
I added the searchBar with this code...
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(-5.0, 0.0, 320.0, 44.0)];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 310.0, 44.0)];
searchBarView.autoresizingMask = 0;
searchBar.delegate = self;
[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBarView;
All of this works perfectly as it should. Now I need to have the UISearchBar disappear when the user ends their editing of the UISearchBar and to be replaced with the titleView's "title" again.
Question
How do I remove the UISearchBar and display the title for the navigation controller after editing?
Try This,
searchBar.hidden = Yes;
I haven't tested it but this should work:
[self.navigationItem.titleView removeFromSuperview];
self.title = #"Nav bar title";

UISearchBar barTintColor not hiding in iOS 7.1

In my app, I am using UISearchBar in a custom UIView.
Following is the code to display the UISearchBar.
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(50, 135, 230, 32)];
searchBar.barTintColor = [UIColor clearColor];
searchBar.placeholder = #"Search";
[self addSubview:searchBar];
In iOS 7.0.3, bartint color not showing,
However in iOS 7.1, the bartint color is not hiding.
It seems that this does the trick:
[searchBar setBackgroundImage:[UIImage new]];

UIToolbar tintColor and barTintColor issues

I have code like so:
UIView *colorView = [[UIView alloc] init];
colorView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 64.0);
colorView.backgroundColor = [UIColor blackColor];
//colorView.tintColor = [UIColor blackColor];
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0);
self.view addSubview:colorView];
[self.view addSubview:toolbar];
Why does the toolbar subview have a different color then my view? The view appears black and the toolbar appears light gray? Is there a blur or something causing this?
Behavior from some of the properties of UINavigationBar has changed from iOS 7. I have already explained this thing in my Answer.
Take a look at the Bar style for iOS 6 and iOS 7 :
You can note two points here :
You can change the Bar style to translucent dark instead of translucent light (default).
You can change the translucent property to NO from YES (default).
Try this code, it will help you,
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0);
toolbar.barStyle = UIBarStyleBlackTranslucent;
toolbar.tintColor = [UIColor blackColor];
toolbar.alpha = 0.0;
Change the tintColor and alpha based on your requirement.

Search Bar in Navigation Bar titleView pops out of UINavigationItem on orientation change?

I have added a search bar to the titleView of my Navigation Bar.
It looks good except for when the orientation changes. For whatever reason the search bar is changing position. It's as if the search bar is popping out or is too big for the Navigation Bar all of a sudden.
Has anyone else had this problem and knows how to fix it? I am using storyboards and was wondering if there is a setting that I am missing or something. Here is my code:
-(void) viewDidAppear:(BOOL)animated
{
UIImage *addImage = [UIImage imageNamed:#"reveal-icon.png"];
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton setFrame:CGRectMake(0, 0, addImage.size.width, addImage.size.height)];
[addButton setBackgroundImage:addImage forState:UIControlStateNormal];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton];
[self.navigationItem setLeftBarButtonItem:barButtonItem];
UIView *searchBarView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 260.0, 44.0)];
searchBarView.autoresizingMask = 0;
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:searchBarView.frame];
searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
searchBar.delegate = self;
[searchBarView addSubview:searchBar];
self.navigationItem.titleView = searchBar;
}

Resources