我有一個UISearchBar問題。在故事板中,其條形色調設置爲clearColor,其搜索樣式爲最小值,條樣式爲默認值。我也有一個自定義背景圖片。iOS - UISearchBar textfield background on focus
這正是我希望它是。
現在,當我按下它來輸入一些文字,會出現以下情況:
背景變成了黑色。如果我取消或停止搜索,它會完美地返回到第一張圖片。 我已經嘗試了很多東西,在代碼中設置所有內容,但我似乎無法更改此黑色背景。我只是想要它是清晰的顏色。
我有一個UISearchBar問題。在故事板中,其條形色調設置爲clearColor,其搜索樣式爲最小值,條樣式爲默認值。我也有一個自定義背景圖片。iOS - UISearchBar textfield background on focus
這正是我希望它是。
現在,當我按下它來輸入一些文字,會出現以下情況:
背景變成了黑色。如果我取消或停止搜索,它會完美地返回到第一張圖片。 我已經嘗試了很多東西,在代碼中設置所有內容,但我似乎無法更改此黑色背景。我只是想要它是清晰的顏色。
好像黑色的背景,由於清除巴色Color.There是沒有必要設置欄色調顏色清除顏色 .SET它如默認。
嘗試在viewDidLoad中
self.searchController.searchBar.barStyle = UIBarStyleBlack;
self.searchController.searchBar.translucent = YES;
這個代碼,我發現,在UISearchController它有這些特性可能影響的UISearchBar的呈現。
@property (nonatomic, assign) BOOL dimsBackgroundDuringPresentation __TVOS_PROHIBITED; // default is YES, and has the same behavior as obscuresBackgroundDuringPresentation.
@property (nonatomic, assign) BOOL obscuresBackgroundDuringPresentation NS_AVAILABLE_IOS(9_1); // default is YES
嘗試將它們設置爲NO
也
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.obscuresBackgroundDuringPresentation = NO;
實際上UISearchBar提供了在Searchbar中設置文本框背景的方法。它是:
- (void)setSearchFieldBackgroundImage:(可爲空的UIImage *)backgroundImage forState:(UIControlState)狀態NS_AVAILABLE_IOS(5_0)UI_APPEARANCE_SELECTOR;
您可以用它來設置任何圖像。
它不會傷心地改變任何事情。 –
Ohhh ..我設置了相同的屬性,它爲我工作。 – Donal
@bloemy你是否啓用traslucent屬性? – Donal