UISearchbar custom in iOS 6 and 7 - ios

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

Related

How to change ring and text color by using SVProgressHUDStyleCustom

I want to show both Ring and Text color of Hud differently.I'm using hud style SVProgressHUDStyleCustom, but unable to achieve the desired result.
My code is following:
[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
[SVProgressHUD setRingThickness:5.0];
[SVProgressHUD setForegroundColor:[UIColor redColor]];
[SVProgressHUD setFont:[UIFont ProximaNovaA_Light:16.0]];
[SVProgressHUD setCornerRadius:3];
[SVProgressHUD setBackgroundColor:[UIColor whiteColor]];
Any help will be welcome.
Try This
[[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.4]];
[[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
[[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:#"MarkerFelt-Wide" size:16]];
[[SVProgressHUD appearance] setHudStatusShadowColor:[UIColor greenColor]];
[SVProgressHUD showSuccessWithStatus:#"Great Success!"];
[[SVProgressHUD appearance] setHudBackgroundColor:[[UIColor greenColor] colorWithAlphaComponent:0.4]];
[[SVProgressHUD appearance] setHudForegroundColor:[UIColor yellowColor]];
[[SVProgressHUD appearance] setHudFont:[UIFont fontWithName:#"MarkerFelt-Wide" size:16]];

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

Unable to change UISearchBar cancel button title color after changing it's text.

I'm using this code to change UISearchBar cancel button title:
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
self.searchDisplayController.searchBar.showsCancelButton = YES;
UIView* view=_otsinguRiba.subviews[0];
for (UIView *subView in view.subviews) {
if ([subView isKindOfClass:[UIButton class]]) {
UIButton *cancelButton = (UIButton*)subView;
if (cancelButton) {
[cancelButton setTitle:#"Test") forState:UIControlStateNormal];
[cancelButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
}
}
}
}
While changing the text works fine, changing the color doesn't. It stays black.
I found the answer to this on SO a while back, but I don't recall where. Here's the code that I'm using to set the color of the text.
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],NSForegroundColorAttributeName,
//[UIColor whiteColor],UITextAttributeTextShadowColor,
//[NSValue valueWithUIOffset:UIOffsetMake(0, 1)],UITextAttributeTextShadowOffset,
nil]
forState:UIControlStateNormal];
You can take advantage of the iOS Runtime Property _cancelButton to achieve this.
UIButton *cancelButton = [self.searchDisplayController.searchBar valueForKey:#"_cancelButton"];
[cancelButton setTitleColor:[UIColor yourColor] forState:UIControlStateNormal];

Set Background Color Globally On On UIButtons

What is the best to change globally all UIButtons background color? I already set the tint globally
[[UIApplication sharedApplication] delegate].window.tintColor =
[[UIButton appearance] setBackgroundImage:[UIImage imageNamed:#"button.png"]
forState:UIControlStateNormal];
Or
[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];
Here's some more info on the appearance proxy: http://developer.apple.com/library/ios/documentation/uikit/reference/UIAppearance_Protocol/Reference/Reference.html
Check this out:
[[UIButton appearance] setBackgroundColor:[UIColor redColor]];

Change font for a programmatically created UISearchBar

I have found that the code in my AppDelegate:
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil]
setFont:[UIFont systemFontOfSize:14]];
works to change the font of a UISearchBar created from IB. No problems there.
However, if I create the UISearchBar in code as such:
UISearchBar *bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
bar.placeholder = #"test";
[self.view addSubview:bar];
Then the above UITextField appearance code has no effect. Is there a way to change the font of a programmatically created UISearchBar?
Thank you!
Try this,It's Working Fine for iOS 5.0 and up: (iOS 7 also)
[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setFont:[UIFont fontWithName:#"League Gothic" size:20]];
You can try this
UITextField *textField = [[searchBar subviews] objectAtIndex:1];
[textField setFont:[UIFont fontWithName:#"Helvetica" size:25]];
for more reference check this
You can use this
UITextField *textField = [self.searchBar valueForKey: #"_searchField"];
[textField setFont:[UIFont fontWithName:#"HelveticaNeue-Light" size:17.0]];
Hope this will help.

Resources