7

我正在使用这个疯狂的代码UITextField作为UISearchBar替代品并“窃取”原始放大镜图标:UISearchBar

    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];
        }
    }

您可能已经猜到了,我不想使用自己的位图。

在 Cocoa 的某个地方没有更容易访问的放大镜图标吗?

4

4 回答 4

25

因此,这是带有 unicode 字符的代码:

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

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

编辑:对于适合 iOS 7 风格的简单外观,添加 Unicode 变体选择器\U000025B6

于 2012-08-05T10:09:33.663 回答
3

我不知道 Cocoa 中有任何标准图像(Unicode 中也没有字符)。

但是,此图像是 Dock 捆绑包的一部分:

/System/Library/CoreServices/Dock.app/Contents/Resources/ectl_search_magnify.png
于 2012-08-05T01:58:40.843 回答
2

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

于 2017-01-27T15:26:47.157 回答
0

使用 OSX 10.7.5 我找不到 ectl_search_magnify.png 但一个简单的

find /System -ipath '*magni*'

成立:

/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).

于 2013-06-27T15:56:41.627 回答