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

后端 未结 4 712
离开以前
离开以前 2020-12-31 20:27

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

相关标签:
4条回答
  • 2020-12-31 20:57

    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.

    0 讨论(0)
  • 2020-12-31 21:03

    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
    
    0 讨论(0)
  • 2020-12-31 21:07

    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.

    0 讨论(0)
  • Using OSX 10.7.5 I couldn't find the ectl_search_magnify.png but a simple

    find /System -ipath '*magni*'
    

    found:

    /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/MagnifyingGlassIcon.icns
    /System/Library/PrivateFrameworks/ProKit.framework/Versions/A/Resources/LionPanels.bundle/Contents/Resources/Dark_NSSmallMagnifyingGlass.tiff
    /System/Library/PrivateFrameworks/ProKit.framework/Versions/A/Resources/LionPanels.bundle/Contents/Resources/Night_NSSmallMagnifyingGlass.tiff
    

    The latter two are probably what you want (assuming you need an image).

    0 讨论(0)
提交回复
热议问题