ios - 在哪里可以获得 UISearchBar 中使用的放大镜图标?

标签 ios cocoa-touch uitextfield uisearchbar

我正在使用 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 中是否有更易于访问的放大镜图标?

最佳答案

所以,这是带有 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

关于ios - 在哪里可以获得 UISearchBar 中使用的放大镜图标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11811705/

相关文章:

ios - 如何在ios中制作文字阴影

iphone - iOS 4.3 模拟器上的 UITextField 自动更正崩溃

ios - swift 用户界面。如何在 ZStack 的顶部放置一个 View ?

ios - 如何在CollectionViewController中为gif设置动画。(Objective-C)

ios - 以编程方式从 iphone 调用 USSD 代码

objective-c - 使图像移动更多 "fluidly"

iOS - 存储用户登录 session 的正确方法

ios - 将框架和应用程序扩展目标添加到 IOS 应用程序项目,我做得对吗?

ios - 删除边框时 TextField 的内容会被修剪

iphone - 多个 Xcode,如何选择打开哪个 xcodeproj 文件