iOS 7 UISearchBar customization when it is first responder - ios

I'm trying add background image on my search bar when it going to navigation bar. But if I'm writing something like this:
self.searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"searchBarBG2.png"]];
there is always black color and it look bad at status bar:
The size of my image is 320:64

For iOS7, try doing
self.searchDisplayController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[self.searchDisplayController.searchBar setBackgroundImage:[self imageWithColor:[UIColor yourColor]] forBarPosition:0 barMetrics:UIBarMetricsDefault];

Try this:
searchBar.backgroundColor = [UIColor clearColor];
searchBar.backgroundImage = [UIImage imageNamed:# searchBarBG2.png"];

Related

UINavigationBar: Adding navigation bar not able to change color or title

I add it a UINavigationBar on interface builder on my story board but I want to change the color and title of the UINavigationBar programmatically but it doesn't work. Here is my code:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.navigationItem.title = #"New Title";
Any of you knows why this happening or a way around this?
I'll really appreciate your help.
Try:
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
These kinds of things can also be done in interface builder when you have access to the reference (and previewed)
try this code
self.navigationController.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName:[UIColor blueColor]};
if you want to change navigation bar background color,
use
self.navigationController.navigationBar.barTintColor
you can also use these code to change the navigationbar in global.
[[UINavigationBar appearance] setBarTintColor:RGB(248, 248, 248)];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:COLOR_NAV_GLOBAL}];
[[UINavigationBar appearance] setBackIndicatorImage:[[UIImage imageNamed:#"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[[UIImage imageNamed:#"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:33.0/255.0 green:30.0/255.0 blue:94.0/255.0 alpha:1.0];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
put this in the view did load method.
first one is for the navigation bar tint color and the second one is for the title font color.

Can't change backgroundcolor of navbar

In my iOS app, I'm using REFRostedViewController (https://github.com/romaonthego/REFrostedViewController) without a storyboard. It's working fine. However, I don't want the navigation bar to be blurred and so I set out to change this. I'm not having any luck though.
I tried setting self.navigationController.navigationbar.background = [UIColor blueColor] in just about any view. That makes the blur blueish.
I've been trying to fix this for about two days. What am I doing wrong?
Please try with following code in where you are initializing your NavigationController
[[UINavigationBar appearance] setTitleTextAttributes: #{
NSBackgroundColorAttributeName: [UIColor blueColor],
}];
Do you want the navigation bar to be transparent then? If you want it to have full alpha try:
self.navigationController.navigationBar.translucent = NO;
You could use:
[navigationController.navigationBar setTintColor:[UIColor redColor]]; //Red as an example.
Try by setting below property of navigaiton nar
self.navigationController.navigationBar.barTintColor = [UIColor yourColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;

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]];

Change Color of navigationBar of just UIActivityViewController

How do you change the colour of only the UIActivityViewController?
I want to change the colour of just the UINavigationBar of the UIActivityViewController using something like:
self.activityViewController.navigationController.navigationBar.barTintColor = [UIColor greenColor];
I would suggest to change the background color of the UINavigationBar before creating and presenting your UIActivityViewController with:
[UINavigationBar appearance].backgroundColor = [UIColor greenColor];
HTH
Following code maybe help you:
[[UINavigationBar appearanceWhenContainedIn:[UIActivityViewController class], nil]
setTintColor:[UIColor greenColor]];

How to change navigation bar color in iOS 7 or 6?

I want to change the color of the navigation bar color, but I'm not sure whether or not I should change the tint or the background. I know iOS 7 is going for a more flat design (even recommending removing gradients), but I am having trouble deciphering the two. Even if I set a background color, it doesn't do anything.
In this image, the background is set to green, but the bar is still blue:
The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView.
To tint the bar's background, please use -barTintColor.
navController.navigationBar.barTintColor = [UIColor navigationColor];
If you want to have a solid color for your navigation bar in iOS 6 similar to iOS 7 use this:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];
in iOS 7 use the barTintColor like this:
navigationController.navigationBar.barTintColor = [UIColor greenColor];
or
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
// In ios 7 :-
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
// In ios 6 :-
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
The background color property is ignored on a UINavigationBar, so if you want to adjust the look and feel you either have to use the tintColor or call some of the other methods listed under "Customizing the Bar Appearance" of the UINavigationBar class reference (like setBackgroundImage:forBarMetrics:).
Be aware that the tintColor property works differently in iOS 7, so if you want a consistent look between iOS 7 and prior version using a background image might be your best bet. It's also worth mentioning that you can't configure the background image in the Storyboard, you'll have to create an IBOutlet to your UINavigationBar and change it in viewDidLoad or some other appropriate place.
One more thing, if you want to change the navigation bg color in UIPopover you need to set barStyle to UIBarStyleBlack
if([UINavigationBar instancesRespondToSelector:#selector(barTintColor)]){ //iOS7
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.barTintColor = [UIColor redColor];
}
Here is how to set it correctly for both iOS 6 and 7.
+ (void)fixNavBarColor:(UINavigationBar*)bar {
if (iosVersion >= 7) {
bar.barTintColor = [UIColor redColor];
bar.translucent = NO;
}else {
bar.tintColor = [UIColor redColor];
bar.opaque = YES;
}
}
The complete code with version checking.
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
}
else {
// do stuff for older versions than iOS 7
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
}
You can check iOS Version and simply set the tint color of Navigation bar.
if (SYSTEM_VERSION_LESS_THAN(#"7.0")) {
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
}else{
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Based on posted answered, this worked for me:
/* check for iOS 6 or 7 */
if ([[self navigationController].navigationBar respondsToSelector:#selector(setBarTintColor:)]) {
[[self navigationController].navigationBar setBarTintColor:[UIColor whiteColor]];
} else {
/* Set background and foreground */
[[self navigationController].navigationBar setTintColor:[UIColor whiteColor]];
[self navigationController].navigationBar.titleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil];
}
you can add bellow code in appdelegate.m .if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:#"FontNAme" size:20],
NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Insert the below code in didFinishLaunchingWithOptions() in AppDelegate.m
[[UINavigationBar appearance] setBarTintColor:[UIColor
colorWithRed:26.0/255.0 green:184.0/255.0 blue:110.0/255.0 alpha:1.0]];
I'm using following code (in C#) to change the color of the NavigationBar:
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.LandscapePhone);
NavigationController.NavigationBar.BackgroundColor = UIColor.Green;
The trick is that you need to get rid of the default background image and then the color will appear.
If you want to change a color of a navigation bar, use barTintColor property of it. In addition, if you set any color to tintColor of it, that affects to the navigation bar's item like a button.
FYI, you want to keep iOS 6 style bar, make a background image looks like previous style and set it.
For more detail, you can get more information from the following link:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
In iOS7, if your navigation controller is contained in tab bar, splitview or some other container, then for globally changing navigationbar appearance use following method ::
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class],nil] setBarTintColor:[UIColor blueColor]];
Try the code below in the - (void)viewDidLoad of your ViewController.m
[[[self navigationController] navigationBar] setTintColor:[UIColor yellowColor]];
this did work for me in iOS 6.. Try it..
I'm not sure about changing the tint vs the background color but this is how you change the tint color of the Navigation Bar:
Try this code..
[navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

Resources