如何更改位置或隐藏IOS 7中的UISearchBar中的放大镜图标?

我正在使用IOS 7应用程序。默认情况下,它出现像Pic(1)。但我需要将其更改为图(2)。我GOOGLE了一下,发现需求的答案很less,但它没有改变。否则我需要以便隐藏。所以我可以用背景图像进行pipe理。这是第一个图像

照片(1)

在这里输入图像说明

我用下面的代码来修改它,但没有成功。

在.h文件中

@property(nonatomic,strong) IBOutlet UISearchBar *findSearchBar; 

在.m文件中

 @synthesize findSearchBar; - (void)viewDidLoad { [super viewDidLoad]; [self setSearchIconToFavicon]; } - (void)setSearchIconToFavicon { // The text within a UISearchView is a UITextField that is a subview of that UISearchView. UITextField *searchField; for (UIView *subview in self.findSearchBar.subviews) { if ([subview isKindOfClass:[UITextField class]]) { searchField = (UITextField *)subview; break; } } if (searchField) { UIView *searchIcon = searchField.leftView; if ([searchIcon isKindOfClass:[UIImageView class]]) { NSLog(@"aye"); } searchField.rightView = nil; searchField.leftView = nil; searchField.leftViewMode = UITextFieldViewModeNever; searchField.rightViewMode = UITextFieldViewModeAlways; } } 

我没有得到如何使视图的中心为零。它真的杀了我的时间。请帮助我,我哪里出了问题。

  UITextField *txfSearchField = [looksearchbar valueForKey:@"_searchField"]; [txfSearchField setBackgroundColor:[UIColor whiteColor]]; [txfSearchField setLeftViewMode:UITextFieldViewModeNever]; [txfSearchField setRightViewMode:UITextFieldViewModeNever]; [txfSearchField setBackground:[UIImage imageNamed:@"searchbar_bgImg.png"]]; [txfSearchField setBorderStyle:UITextBorderStyleNone]; //txfSearchField.layer.borderWidth = 8.0f; //txfSearchField.layer.cornerRadius = 10.0f; txfSearchField.layer.borderColor = [UIColor clearColor].CGColor; txfSearchField.clearButtonMode=UITextFieldViewModeNever; 

试试这可能会帮助你……..

我不知道如何左alignment占位符,但是从iOS 5.0开始,有一种简单的支持方法来修改search栏的文本字段属性,例如:

 [[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setLeftViewMode:UITextFieldViewModeNever]; 

这将隐藏放大镜图标。

你可以尝试:

 searchBar.setImage(UIImage(named: "yourimage")!, forSearchBarIcon: UISearchBarIcon.Clear, state: UIControlState.Normal)