Created
February 15, 2010 06:55
-
-
Save henrik/304457 to your computer and use it in GitHub Desktop.
Replace the magnifying glass icon in an iPhone UISearchBar with a custom image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface SearchBoxExperimentsViewController : UIViewController { | |
IBOutlet UISearchBar *searchBar; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "SearchBoxExperimentsViewController.h" | |
@interface SearchBoxExperimentsViewController (Private) | |
- (void)setSearchIconToFavicon; | |
@end | |
@implementation SearchBoxExperimentsViewController | |
- (void)viewDidLoad { | |
[self setSearchIconToFavicon]; | |
[super viewDidLoad]; | |
} | |
#pragma mark Private | |
- (void)setSearchIconToFavicon { | |
// Really a UISearchBarTextField, but the header is private. | |
UITextField *searchField = nil; | |
for (UIView *subview in searchBar.subviews) { | |
if ([subview isKindOfClass:[UITextField class]]) { | |
searchField = (UITextField *)subview; | |
break; | |
} | |
} | |
if (searchField) { | |
UIImage *image = [UIImage imageNamed: @"favicon.png"]; | |
UIImageView *iView = [[UIImageView alloc] initWithImage:image]; | |
searchField.leftView = iView; | |
[iView release]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment