如何更改UISearchBar以使用文本替换文本字段内的搜索图标 [英] how to change the UISearchBar to replace the search icon inside the text field with text

查看:102
本文介绍了如何更改UISearchBar以使用文本替换文本字段内的搜索图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有UISearchBar,我想删除搜索标记(放大镜图标)并放置文本而不是它

I have UISearchBar and I want to remove the search marker(magnifier icon) and put a text instead of it

推荐答案

您可以通过以下方式更改放大图标,根据您的需要进行调整: -

You Can Change the magnify Icon in the following way , adapt it to your needs :-

#import <UIKit/UIKit.h>

@interface SearchBoxExperimentsViewController : UIViewController {  
    IBOutlet UISearchBar *searchBar;
}
@end 

#import "SearchBoxExperimentsViewController.h"
@interface SearchBoxExperimentsViewController (Private)
- (void)setSearchIconToFavicon;
@end

@implementation SearchBoxExperimentsViewController
- (void)viewDidLoad 
{  
    [self setSearchIconToFavicon];  
    [super viewDidLoad];
}

#pragma mark Private
- (void)setSearchIconToFavicon 
{  
    // Really a UISearchBarTextField, but the header is private.  
    UITextField *searchField = nil;  
    for (UIView *subview in searchBar.subviews) {    
        if ([subview isKindOfClass:[UITextField class]]) {      
            searchField = (UITextField *)subview;      
            break;    
        }  
    }    
    if (searchField) {      
        UIImage *image = [UIImage imageNamed: @"favicon.png"];   
        UIImageView *iView = [[UIImageView alloc] initWithImage:image];    
        searchField.leftView = iView;    
        [iView release];  
    }  
}
@end 

它对我有用: )

这篇关于如何更改UISearchBar以使用文本替换文本字段内的搜索图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆