簡體   English   中英

如何在IOS 7中更改UISearchBar中的位置或隱藏放大鏡圖標?

[英]How to change the position or hide magnifier icon in UISearchBar in IOS 7?

我正在研究IOS 7應用程序。默認情況下它看起來像Pic(1)。但是我需要將其更改為Pic(2)。我用谷歌搜索並找到了幾個答案的要求,但它沒有改變。或者我需要隱藏。所以我可以用背景圖像管理。這是第一張圖片

照片(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;

試試這可能會對你有所幫助........

我不確定如何左對齊占位符,但從iOS 5.0開始,有一種簡單的,支持的方式來修改搜索欄的文本字段屬性,例如:

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

這將隱藏放大鏡圖標。

你可以嘗試:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM