Change the position of backgroundImage when clicked on searchBar - ios

I have a background image in my search bar:
self.searchBar.scopeButtonTitles=nil;
self.searchBar.showsScopeBar=NO;
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:#"search-icon-1"]forState:UIControlStateNormal];
[self.searchBar.layer setBorderWidth:1];
[self.searchBar.layer setBorderColor:RGB(200,200,200).CGColor];
self.searchBar.layer.cornerRadius=12;
[self.searchBar sizeThatFits:CGSizeMake(216, 56)];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setLeftViewMode:UITextFieldViewModeNever];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setFont:opensans2];
By default, when I clicked on my search bar, my background image is moved to the left.
How can I replace it on the center ? ( -> How can i access to the variable background offset horizontal, which is present in the storyboard, programmatically?)

Related

ABPeoplePickerNavigationController search bar color and doesn't get changed

I'm trying to change the color of the search bar orange and the bar tint color to white when a contact get selected.
No matter what I've been trying, nothings get changed and it's stuck like this (back button isn't white).
in AppDelegate:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearanceWhenContainedIn:[UINavigationController class], nil] setBarTintColor:OrangeOfficialColor];
[[UINavigationBar appearance] setBarTintColor:OrangeOfficialColor];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
When popping the view:
ABPeoplePickerNavigationController *contactsPicker = [[ABPeoplePickerNavigationController alloc] init];
contactsPicker.peoplePickerDelegate = self;
contactsPicker.displayedProperties = #[[NSNumber numberWithInt:kABPersonPhoneProperty]];
[contactsPicker.searchDisplayController.searchBar setBarTintColor:OrangeOfficialColor];
[contactsPicker.searchDisplayController.searchBar setTintColor:[UIColor whiteColor]];
[self presentViewController:contactsPicker animated:YES completion:nil];
View is OK:
View isn't OK:
View isn't OK:
I had the same issue once I started using Xcode 6 (iOS 8 SDK) and iOS 7 apps. This was my workaround fix:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:#{NSFontAttributeName : [UIFont fontWithName:#"HelveticaNeue" size:16.0f], NSForegroundColorAttributeName : [UIColor blueColor]} forState:UIControlStateNormal];

UISearchBar text color when used in UISearchDisplayController

i'm trying to change a UISearchbar text color in iOS7 app. (i want the text to be white).
the search bar is attached to a searchDisplay controller.
i have tried many options, including this one:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], [FVRNavigationBar class], nil] setTextColor:[UIColor whiteColor]];
also tried setTintColor:, and setBarTintColor:. Nothing works.
Note, this solutions does work when the search bar is not attached to a displayController.
FYI, not that i think it matters, but i use a background image for my search bar.
in addition, the searchbar is placed in my navigationBar.
here is my code:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], [FVRNavigationBar class], nil] setTextColor:[UIColor whiteColor]];
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 52)];
[_searchBar setSearchFieldBackgroundImage:[IMAGE(#"searchBarBg") resizableImageWithCapInsets:UIEdgeInsetsMake(8, 8, 8, 8)] forState:UIControlStateNormal];
_displayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
_displayController.delegate = self;
_displayController.displaysSearchBarInNavigationBar = YES;
I'd appreciate anyones help. thanks!

Active UISearchBar makes status bar background black

I have a UISearchBar at the top of UITableView which works great. I've been trying to customise its appearance and there is an issue when the search bar is active - it turns the status bar background colour to black. I tried the suggestions in IOS7 Status bar change to black after search is active but it didn't work for me.
App is iOS 7-only. UISearchBar is to to Minimal Search Style and Default Bar Style, translucent and default barTintColor. I've customised its appearance in my AppDelegate as follows:
[[UISearchBar appearance] setBarTintColor:AAColorInputBorder];
[[UISearchBar appearance] setBackgroundColor:AAColorInputBorder];
[[UILabel appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTextColor:[UIColor whiteColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil]
setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[UIFont fontWithName:#"Avenir" size:16], NSFontAttributeName,
nil] forState:UIControlStateNormal];
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:#"Avenir" size:14]];
Does anyone have any idea on how to change the status bar background color? I want it to match the colour of the UISearchBar.
Thanks!
This is a little hack I use to extend the UISearchBar color
on viewDidLoad()
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
[self removeUISearchBarBackgroundInViewHierarchy:self.searchDisplayController.searchBar];
method:
- (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];
}
}
}

UISearchbar custom in iOS 6 and 7

I want my UISearchbar should look like this.
i've tried this:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:#"Helvetica Neue" size:20]];
[self.seachBar setSearchFieldBackgroundImage:[UIImage imageNamed:#"background"] forState:UIControlStateNormal];
[self.seachBar setImage:[UIImage imageNamed:#"SearchIcon"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
[self.seachBar setBackgroundImage:[UIImage imageNamed:#"background"]];
[self.seachBar setText:#"Search"];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Please guide or any tutorial.
Thanks
Try this code
for (UIView *searchBarSubview in [searchBar subviews])
{
if ([searchBarSubview conformsToProtocol:#protocol(UITextInputTraits)])
{
[[UISearchBar appearance] setSearchFieldBackgroundImage:[UIImage imageNamed:#"background"]forState:UIControlStateNormal];
[(UITextField *)searchBarSubview setBorderStyle:UITextBorderStyleNone];
[[UISearchBar appearance] setBackgroundImage:[UIImage imageNamed:#"search"]];
[[UISearchBar appearance] setTintColor:[UIColor clearColor]];
}
}
Hope, your problem solved...
refer below link it more helpful you don't waste your valuable time
Right align magnifying glass icon in UISearchBar

How to change text color of table header on iOS 5?

How to change text color of table header on iOS 5 without using viewForHeaderInSection to create entire header view?
Add on viewDidLoad:
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setTextColor:[UIColor whiteColor]];
[[UILabel appearanceWhenContainedIn:[UITableViewHeaderFooterView class], nil] setShadowColor:[UIColor clearColor]];

Resources