Ios6 如何更改UICollectionView中的导航栏背景

Ios6 如何更改UICollectionView中的导航栏背景,ios6,uinavigationbar,uicollectionview,Ios6,Uinavigationbar,Uicollectionview,我有一个项目,有十几个不同的视图控制器。所有人都使用相同的代码设置其导航栏的背景,如下所示: CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:28]].width, 44); UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame]; titleLabel.text =

我有一个项目,有十几个不同的视图控制器。所有人都使用相同的代码设置其导航栏的背景,如下所示:

CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:28]].width, 44);
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    titleLabel.text = @"Categories";
    titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:22];
    titleLabel.backgroundColor = UIColorFromRGBWithAlpha(0x84A537, 0.5);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;

    self.navigationController.navigationBar.tintColor = UIColorFromRGBWithAlpha(0x84A537, 0.5);
    self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
    self.navigationController.view.backgroundColor = UIColorFromRGBWithAlpha(0x84A537, 0.1);
它们都可以正常工作,但CollectionView的标题文本背景为灰色。我复制并粘贴了其他VCs的代码。我不知道我是怎么做的。我设置颜色十六进制值如下:

//RGB color macro
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

集合视图的导航栏样式设置似乎与其他视图控制器不同。对于这些,我必须在呼叫控制器中设置条颜色,并设置导航。将集合视图中的背景颜色栏设置为clearColor

我希望这能帮助别人

呼叫VC:

- (IBAction)imageButtonTapped:(id)sender {
    imageCellLayout = [[ImageCellLayout alloc] init];

    imageViewController= [[ImageViewController alloc] initWithCollectionViewLayout:imageCellLayout];
    imageViewController.item = item;
    addImageViewController.item = item;
    imageViewController.collectionView.pagingEnabled = YES;
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:imageViewController];
    nc.navigationBar.tintColor =  UIColorFromRGBWithAlpha(0xC43F32, 0.5);
    nc.modalPresentationStyle = UIModalPresentationPageSheet;
    [self presentViewController:nc animated:YES completion:nil];

}
集合视图:

//Title Stuff

CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont fontWithName:@"HelveticaNeue" size:28]].width, 44);
UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
NSString *tempTitle = item.title;
titleLabel.text = tempTitle;
titleLabel.font = [UIFont fontWithName:@"HelveticaNeue" size:22];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
self.navigationItem.titleView = titleLabel;