Skip to content

Commit

Permalink
[TIMOB-18143] Addressed comments of PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pec1985 committed May 11, 2015
1 parent eaa2321 commit b59bcea
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions iphone/Classes/TiUISearchBar.m
Expand Up @@ -141,17 +141,19 @@ -(void)setBarColor_:(id)value
-(void)setBackgroundImage_:(id)arg
{
UIImage *image = [self loadImage:arg];
if([TiUtils isIOS7OrGreater]) {
// reset the image to nil so we can check if the next statement sets it
[[self searchBar] setBackgroundImage:nil];
// try to set the image with UIBarMetricsDefaultPrompt barMetrics
[[self searchBar] setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefaultPrompt];
// check that the image has been set, otherwise try the other barMetrics
if([[self searchBar] backgroundImage] == nil) {
[[self searchBar] setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
}
} else {
[[self searchBar] setBackgroundImage:image];
UISearchBar* searchBar = [self searchBar];
// reset the image to nil so we can check if the next statement sets it
[searchBar setBackgroundImage:nil];

// try to set the image with UIBarMetricsDefaultPrompt barMetrics
//
// Checking for the `prompt` property is not reliable, even if it's not set, the height
// of the searchbar determines wheather the barMetrics is `DefaultPrompt` or just `Default`
[searchBar setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefaultPrompt];

// check that the image has been set, otherwise try the other barMetrics
if([searchBar backgroundImage] == nil) {
[searchBar setBackgroundImage:image forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
}
self.backgroundImage = arg;
}
Expand Down

0 comments on commit b59bcea

Please sign in to comment.