如何在IOS 7中更改UISearchBar中的位置或隐藏放大镜图标? [英] How to change the position or hide magnifier icon in UISearchBar in IOS 7?

查看:554
本文介绍了如何在IOS 7中更改UISearchBar中的位置或隐藏放大镜图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究IOS 7应用程序。默认情况下它看起来像Pic(1)。但是我需要将其更改为Pic(2)。我用谷歌搜索并找到了几个答案,但它没有改变。或者它没有改变。或者否则我需要隐藏。所以我可以用背景图像管理。这是第一张图片

I am working on IOS 7 application.By default its appearing like Pic(1).But I need to change it as Pic(2).I googled and found few answers for the requirement,but it has not changed.Or else I need to hide.So that I can manage with background image.This is first image

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

I used below code to modify it.But didnt succeed.

在.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;
}

}

我没有得到如何制作它的视图中心到了nil。它真的让我的时间过去了。请帮助我。我出错了。

I am not getting how to make the center of the view's image to nil.Its really killing my time.Please help me.where I had gone wrong.

推荐答案

    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;

尝试这可能会对你有帮助........

Try this may be it will help u........

这篇关于如何在IOS 7中更改UISearchBar中的位置或隐藏放大镜图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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