2012-07-16 6 views
0

StoryBoard에서 iOS 5.1을 사용하고 있습니다. 표준 페이지 컬 버튼의 색조를 변경하고 싶지만 너무 능숙하지 않은 것 같습니다.UIBarButtonSystemItemPageCurl 항목 색조를 변경할 수없는 이유는 무엇입니까?

버튼은보기 컨트롤러에 있으며 내비게이션 컨트롤러의 밀어 넣기보기 컨트롤러입니다. 내비게이션 컨트롤러에서 색조를 변경함에 따라 툴바가 유추됩니다. 도구 모음이 원하는 색상으로 나타납니다. 다음

내 viewDidLoad에 방법은 다음

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // adjust the color of the curl button 
    if (self.curlButton) { 
     NSMutableArray * toolbarItems = [self.toolbarItems mutableCopy]; 
     [toolbarItems removeObject:self.curlButton]; 
     UIColor *barColor = self.navigationController.toolbar.tintColor; 
     UIBarButtonItem *newPageCurl = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self.curlButton.target action:self.curlButton.action]; 
     newPageCurl.tintColor = barColor; 
     NSLog(@"%@", newPageCurl.tintColor); 
     [toolbarItems addObject:newPageCurl]; 
     self.toolbarItems = toolbarItems; 
    } 
} 

self.curlButton 인터페이스 빌더로 구성된 페이지 넘기기 버튼의 출구이다.

처음에는 색조를 self.curlButton으로 설정했는데 초기에는 0으로 설정했지만 작동하지 않으면 버튼이 동일한 파란색 색조였습니다.

여기에 대한 답변 중 일부는 프로그래밍 방식으로 새 버튼을 만들어야한다고 말합니다. 이것이 내가 여기서 시도하는 것입니다.

barColor에 올바른 색이 포함되어 있는지 확인했습니다. 나는 removeObject 라인을 주석 처리했으며 정확하게 두 개의 컬 버튼을 생성했지만 모두 파란색이었습니다.

NSLog는 newPageCurl 버튼에 올바른 색조 세트가 있는지 확인합니다.

대신 도구 모음을 먼저 표시해야하지만 단추가 여전히 파란색이고 새 색조를 사용하지 않은 경우이 모든 작업을 viewDidAppear에서 수행했습니다.

답변

0

iOS 5에서 시작하면 모양 선택기를 사용하여이 작업을 수행 할 수 있습니다.

(편집, 유감스럽게도 wrt curl 버튼을 사용하지 못하게했습니다. 모양 또는 모양 .WhenContainedIn : 컬 버튼을 제외한 모든 항목에 대해 작동합니다 ... 컬링 용으로 한 시스템 사용자는 UIBarButtonSystemItem PageCurl does not change color with the toolbar 작동했지만 테스트 한 결과 나에게 도움이되지 못했습니다.)

if ([[UIBarButtonItem class] respondsToSelector:@selector(appearanceWhenContainedIn:)]) 
    { 
     id barButtonAppearance 
      = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]; 
     [barButtonAppearance setTintColor:self.navigationController.toolbar.tintColor]; 
     barButtonAppearance 
      = [UIBarButtonItem appearanceWhenContainedIn:[UIToolBar class], nil]; 
     // you'll have to have toolbar already, or pick something like [UIColor chartreuseColor] or whatever 
     [barButtonAppearance setTintColor:toolbar.tintColor]; 
    } 
+0

불행하게도 페이지 컬 버튼의 색상은 변경되지 않습니다. 표준 단추 아이콘을 도구 모음의 흰색에서 틴트 색으로 변경하면 원치 않는 부작용이 생깁니다. – Peter

+0

이 업데이트되어 실제 솔루션을위한 링크와 더 나은 솔루션을 제공합니다. 단추가 해당 막대에서만 바뀌는 지 확인하십시오. –

+0

흠 ... 아마 나는이 질문을 포기해야한다. 난 그냥 링크 된 답변에서 자신을 제안을 시도하고 연결된 대답의 사용자가 그를 위해 일했다는 동안, 그것은 나를 위해 작동하지 않았다. –