我試圖在導航欄上添加我的搜索欄上的背景圖像。但是,如果我寫的東西是這樣的:iOS 7 UISearchBar當它是第一響應者時的自定義
self.searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"searchBarBG2.png"]];
總有黑色,並在狀態欄上看起來很糟糕:
我的圖像尺寸是320:64
我試圖在導航欄上添加我的搜索欄上的背景圖像。但是,如果我寫的東西是這樣的:iOS 7 UISearchBar當它是第一響應者時的自定義
self.searchDisplayController.searchBar.barTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"searchBarBG2.png"]];
總有黑色,並在狀態欄上看起來很糟糕:
我的圖像尺寸是320:64
對於iOS7,嘗試做
self.searchDisplayController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
[self.searchDisplayController.searchBar setBackgroundImage:[self imageWithColor:[UIColor yourColor]] forBarPosition:0 barMetrics:UIBarMetricsDefault];
以前我只用'setBackgroundImage'沒有指標和位置。這是完美的工作。謝謝! –
試試這個:
searchBar.backgroundColor = [UIColor clearColor];
searchBar.backgroundImage = [UIImage imageNamed:@ searchBarBG2.png"];
我試過了。但是,它在搜索欄不是第一響應者時起作用。 –
如果添加上面的'searchBar.backgroundColor = [UIColor clearColor];' –
以編程方式添加搜索欄? –
不,通過故事板中的界面生成器 –
是dat搜索欄還是搜索顯示控制器? –