Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I get the magnifying glass icon used in UISearchBar?

I'm using UITextField as a UISearchBar replacement and "stealing" the magnifying glass icon from the original UISearchBar with this crazy code:

    UISearchBar *originalSearchBar = [[UISearchBar alloc] init];
    for (UIView *searchBarSubview in [originalSearchBar subviews]) {
        if([searchBarSubview isKindOfClass:[UITextField class]]) {
            UITextField *textField = (UITextField *)searchBarSubview;
            [_textField setLeftView:[textField leftView]];
            [_textField setLeftViewMode:UITextFieldViewModeAlways];
        }
    }

As you've probably guessed, I don't want to use my own bitmap.

Isn't there an easier accessible magnifying glass icon somewhere in Cocoa?

like image 812
Rudolf Adamkovič Avatar asked Aug 04 '12 20:08

Rudolf Adamkovič


Video Answer


3 Answers

So, here's the code with the unicode character:

    UILabel *magnifyingGlass = [[UILabel alloc] init];
    [magnifyingGlass setText:[[NSString alloc] initWithUTF8String:"\xF0\x9F\x94\x8D"]];
    [magnifyingGlass sizeToFit];

    [textField setLeftView:magnifyingGlass];
    [textField setLeftViewMode:UITextFieldViewModeAlways];

Edit: For plain look that fits iOS 7 style, add Unicode variation selector \U000025B6.

like image 133
Rudolf Adamkovič Avatar answered Oct 17 '22 23:10

Rudolf Adamkovič


I don't know of any standard image for it in Cocoa (and there is no character for it in Unicode either).

An image for this is part of the Dock bundle, however:

/System/Library/CoreServices/Dock.app/Contents/Resources/ectl_search_magnify.png
like image 28
Kevin Grant Avatar answered Oct 17 '22 23:10

Kevin Grant


As I couldn't get a plain unicode magnifying glass to appear, I decided to see what a standard UISearchBox uses. It turns out it's an image of a magnifying glass, which I've extracted and included below, though it's a very simple shape which would be trivial to reproduce perfectly.

2x Search 3x Search

like image 23
Robert Avatar answered Oct 18 '22 00:10

Robert