2013-03-06 4 views
0

12 개의 다른보기 컨트롤러가있는 프로젝트가 있습니다.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의 코드를 복사하여 붙여 넣었습니다. 나는 이것을하기 위해 내가 뭘하는지 모르겠다. 다음과 같이 색상 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] 

답변

1

컬렉션보기의 탐색 모음 스타일 설정이 다른보기 컨트롤러와 다릅니다. 이를 위해 호출하는 컨트롤러에서 막대 색상을 설정하고 nav를 설정해야했습니다. 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; 
관련 문제