Question

Basically I am trying to set the background color of my UINavigationBar but it doesn't show anything whatsoever.

Please, how can I fix this ?! Thanks a Million !!

This is my code in 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];
Était-ce utile?

La solution

This works fine with iOS 7, and you adapt to your code above:

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];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top