1

基本上我試圖設置我的UINavigationBar的背景顏色,但它不顯示任何內容。UICollection視圖隱藏UINavigationBar

請問我該如何解決這個問題?太感謝了 !!

這是我的代碼在viewDidLoad

[super viewDidLoad]; 



self.filteredContentList = [[NSMutableArray alloc] init]; 
// Do any additional setup after loading the view. 

self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 50, CGRectGetWidth(self.collectionView.frame), 30)]; 
self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo; 
self.searchBar.placeholder = @"Search..."; 

[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:CellIdentifier]; 
self.collectionView.backgroundColor = [UIColor whiteColor]; 

[self.collectionView addSubview:self.searchBar]; 
[self.view addSubview:self.searchBar]; 
[self.collectionView setContentOffset:CGPointMake(0, 44)]; 

[self.collectionView setContentInset:UIEdgeInsetsMake(80, 0, 0, 0)]; 

self.navigationController.navigationBar.backgroundColor = [UIColor greenColor]; 
+0

什麼IOS版本您使用的? – Winston

+0

@Winston目前使用iOS7 – ipalibowhyte

回答

1

能正常工作與iOS 7,你適應你上面的代碼:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]; 
[navBar setBarTintColor:[UIColor greenColor]]; 

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 50, CGRectGetWidth(navBar.frame), 30)]; 
searchBar.autocorrectionType = UITextAutocorrectionTypeNo; 
searchBar.placeholder = @"Search..."; 

[self.view addSubview:searchBar]; 
[self.view addSubview:navBar]; 
+0

非常感謝:D! – ipalibowhyte

+0

不客氣! – Winston