Color has changed in iOS7.1, how to change the color of the search bar?

On iOS7.0.3 - 7.0.6, my searchBar color is Gold / yellow as follows: enter image description here

But on iOS 7.1, the color becomes something like this:

enter image description here

I have installed

searchBar.tintColor = [UIColor clearColor];
searchBar.backgroundColor = goldColor;
searchBar.tintColor = [UIColor blackColor];

I tried so many ways and it all failed. Can someone figure out what changes are in iOS 7.1?

=============== My fix ================

I fix this problem by closing the view on the searchBar and adding the search text presented as a subview on this new view.

I need to indicate that the gold status bar is a subView of searchBar, and the frame CGRectMake(0, -20, 320, 20)and the background color is gold.

First I installed this:

_searchBar.translucent = YES;
_searchBar.scopeBarBackgroundImage = [self imageWithColor:UWGold];

and looks like this:

enter image description here

Then I expand the window for viewing the status bar, I changed the height of the presentation frame.size.height + searchBar, then I use this line:

UITextField *textSearchField = [_searchBar valueForKey:@"_searchField"];

textSearchField, SearchField .

, searchBar , iOS 7.0

enter image description here

, , iOS 7.1 .

+4
3

:

if(IOS_7)
{
self.searchBar.searchBarStyle = UISearchBarStyleMinimal;
self.searchBar.backgroundImage = [UIImage imageWithColor:[UIColor redColor] cornerRadius:5.0f];
}

, .

+4

iOS 7/8. , :

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 44)];
searchBar.scopeButtonTitles = @[@"Scope1", @"Scope2"];
searchBar.selectedScopeButtonIndex = 0;
searchBar.backgroundColor = [UIColor clearColor];
searchBar.barTintColor = [UIColor clearColor];
searchBar.translucent = YES; // SUPER IMPORTANT, REMOVING THIS MESSED UP THE SCOPE BAR

// ONLY USE IMAGES, NOT BACKGROUND COLORS
UIImage *searchBarBackgroundImage = [[UIImage imageNamed:@"SearchBarBackgroundImage"];
UIImage *scopeBarBackgroundImage = [[UIImage imageNamed:@"ScopeBarBackgroundImage"];
[searchBar setBackgroundImage:searchBarBackgroundImage
               forBarPosition:UIBarPositionAny
                   barMetrics:UIBarMetricsDefault];
searchBar.scopeBarBackgroundImage = scopeBarBackgroundImage;
searchBar.tintColor = [UIColor whiteColor];
+2

backgroundColor searchBar

1. @Ben Jackson - set BackgroundImage

[self.searchBar setBackgroundImage:[self imageWithColor:[UIColor blueColor]] forBarPosition:UIBarPositionAny
                        barMetrics:UIBarMetricsDefault];

2.Change the textField that you need by design

NSArray *searchBarSubViews = [[self.searchBar.subviews objectAtIndex:0] subviews];
for( int i = 0; i < searchBarSubViews.count; i++) {
    if([[searchBarSubViews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
        UITextField *searchTextField = (UITextField *)[searchBarSubViews objectAtIndex:i];
        [searchTextField setTintColor:[UIColor blueColor]];
        searchTextField.placeholder = @"Search";
        searchTextField.backgroundColor = [UIColor whiteColor];
        searchTextField.layer.borderColor = [UIColor blueColor].CGColor;
        searchTextField.layer.borderWidth = 1.0f;
        searchTextField.layer.cornerRadius = 8.0f;
        searchTextField.leftViewMode = UITextFieldViewModeNever;
    }
}

Also the color image method is here.

Result:

enter image description here

enter image description here

0
source

Source: https://habr.com/ru/post/1531092/


All Articles