我正在使用 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/