Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-18143] iOS Fixed searchbar background image #6752

Merged
merged 3 commits into from
May 12, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions iphone/Classes/TiUISearchBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,24 @@ -(void)setBarColor_:(id)value
-(void)setBackgroundImage_:(id)arg
{
UIImage *image = [self loadImage:arg];
[[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;
}

#pragma mark Delegate
#pragma mark Delegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
if (delegate!=nil && [delegate respondsToSelector:@selector(searchBarShouldBeginEditing:)]) {
Expand Down