0
我有一个有十几个不同视图控制器的项目。所有使用相同的代码来设置其导航栏的背景如下:如何更改UICollectionView中的导航栏背景
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。我已经复制并粘贴了其他VC的代码。我不知道我在做什么来造成这种情况。我设置像这样的颜色十六进制值:
//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]