0

12 種類のビュー コントローラーを含むプロジェクトがあります。すべて同じコードを使用して、次のようにナビゲーション バーの背景を設定します。

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 からコードをコピーして貼り付けました。これを引き起こすために何をしているのかわかりません。次のように色の 16 進値を設定します。

//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]
4

1 に答える 1

1

コレクション ビューのナビゲーション バー スタイルの設定が他のビュー コントローラーと異なるようです。これらの場合、呼び出し元のコントローラーでバーの色を設定し、ナビゲーションを設定する必要がありました。コレクション ビューのバーの背景色を 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;
于 2013-03-07T23:24:29.120 に答える