Changing UISearchBar Button Color

To change the UISearchBar button color, the simplest approach is to change the Tint color in it’s View section using storyboard.

However, it will also affect the insertion point color.

So if you want a white color button, the insertion point will disappear because is the same color as the search bar background…

To tackle this problem, we can configure the appearance of the search bar using its appearance proxy in the app delegate:

[code lang=objc]
NSDictionary *attrDict = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
UIBarButtonItem *buttonItemProxy = [UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil];
[buttonItemProxy setTitleTextAttributes:attrDict forState:UIControlStateNormal];
[/code]

This will only change the color of the button but not the insertion point.

Note that this approach will affect all search bars in your app.

38

Tab Bar Background Color and Button Tint Color

To change the background color of tab bar, we can change the tab bar setting in storyboard.

However, unlike navigation bar, we cannot setting the tab bar item’s tint color inside storyboard.

We have to add some code in the app delegate, inside application:didFinishLaunchingWithOptions:, add

[code lang=objc]
[[UITabBar appearance] setTintColor:[UIColor yellowColor]];
[/code]

Note that this is an application-wide setting, all tab bar items will tint to the specific color.

34

Hide Status Bar

Starting from iOS 7, there are 2 ways to hide the status bar. One is to hide the status bar in all view controllers, while the other is controller specific.

  1. App-based setting

Set “View controller-based status bar appearance” in target’s info to NO.

then in the app delegate, inside application:didFinishLaunchingWithOptions:, add

[code lang=objc]
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[/code]

  1. Controller-based setting

Set “View controller-based status bar appearance” to YES.

Inside viewDidLoad, add

[code lang=objc]
[self setNeedsStatusBarAppearanceUpdate]
[/code]

and then add the following function:

[code lang=objc]
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
[/code]

14