ios - UICollectionview 隐藏导航栏

标签 ios objective-c cocoa-touch uinavigationcontroller uicollectionview

基本上我正在尝试设置我的 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];

最佳答案

这适用于 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];

关于ios - UICollectionview 隐藏导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23146000/

相关文章:

ios - 如何以编程方式从 Storyboard 中填充静态 UITableView?

ios - Here Maps - iOS 高级版- infoBubble

iPhone 3.1 SDK 相机访问

iphone - 控制主音量 - iPhone、Cocoa Touch

objective-c - 随着 uiimageview 的旋转调整 uiview 的大小

ios - 如何向 NSLinguisticTagger 添加名称?

objective-c - QLPreviewController 因大文档而崩溃

ios - 为 TableView 中的所有单元格设置标签的正确方法

ios - 如何处理: UIActionSheet deprecated (iOS8) X UIAlertController not supported (iOS7)

ios - 如何设置具有变化延迟的 NSTimer?