2014-02-18 64 views
1

我試圖在導航欄上添加我的搜索欄上的背景圖像。但是,如果我寫的東西是這樣的:iOS 7 UISearchBar當它是第一響應者時的自定義

self.searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"searchBarBG2.png"]]; 

總有黑色,並在狀態欄上看起來很糟糕:enter image description here

我的圖像尺寸是320:64

+0

以編程方式添加搜索欄? –

+0

不,通過故事板中的界面生成器 –

+0

是dat搜索欄還是搜索顯示控制器? –

回答

2

對於iOS7,嘗試做

self.searchDisplayController.searchBar.searchBarStyle = UISearchBarStyleMinimal; 

[self.searchDisplayController.searchBar setBackgroundImage:[self imageWithColor:[UIColor yourColor]] forBarPosition:0 barMetrics:UIBarMetricsDefault]; 
+0

以前我只用'setBackgroundImage'沒有指標和位置。這是完美的工作。謝謝! –

1

試試這個:

searchBar.backgroundColor = [UIColor clearColor]; 
searchBar.backgroundImage = [UIImage imageNamed:@ searchBarBG2.png"]; 
+0

我試過了。但是,它在搜索欄不是第一響應者時起作用。 –

+0

如果添加上面的'searchBar.backgroundColor = [UIColor clearColor];' –

相關問題