2012-06-03 88 views
1

所以我想建立一個自定義圖像使用下面的代碼我UISearchField圖像:的UISearchBar setSearchFieldBackgroundImage問題

UISearchBar * searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 300, 44)]; 
    searchBar.placeholder = @"Search for a tag"; 
    searchBar.delegate = self; 
    [searchBar setSearchFieldBackgroundImage:[UIImage imageNamed:@"search-bg.png"] forState:UIControlStateNormal]; 
    UITextField *searchField = [searchBar valueForKey:@"_searchField"]; 
    searchField.textColor = [UIColor whiteColor]; 

但是也有一些是錯誤的放大鏡,我有。結果如下:

enter image description here

如果你看到密切放大鏡實際上是透明的,而不是白色。在圖像中,我將它設置爲白色。任何想法,爲什麼這可能會發生?

回答

1

我不知道是怎麼回事,但是你可以提供自己的放大鏡圖像:

[self setImage:[UIImage imageNamed:@"glassImage"] forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];