2011-09-29 1 views

답변

0

this post on Stack Overflow에서 설명한대로, 하위 클래스 UITabBarController는 - (void) viewDidLoad 메서드를 재정의합니다. 다음 예는 다음과 같습니다 또한

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    // Alternate between red and blue. Obviously this is a pretty terrible example, 
    // since the number of items shouldn't be a fixed integer. Replace this 
    // with whatever you want to do with your UITabBarItems. 

    int colorIndex = 0; 
    NSArray *colorArray = [NSArray arrayWithObjects:[UIColor redColor], [UIColor blueColor], nil]; 
    for (int itemIndex = 0; itemIndex < 3; itemIndex++) { 
     // Create a frame for a subview which will overlap over the UITabBarItem. 
     CGRect frame = CGRectMake((self.tabBar.bounds.size.width/2.0)*itemIndex, 
            0.0, 
            self.tabBar.bounds.size.width/2.0, 
            self.tabBar.bounds.size.height); 
     // Initialize a UIView using the above frame. 
     UIView *v = [[UIView alloc] initWithFrame:frame]; 

     // Cycle through the colors. 
     if (++colorIndex >= [colorArray count]) { 
      colorIndex = 0; // Keep colorIndex from going out of bounds. 
     } 

     // Set alpha to 0.5 so OP can see the view overlaps over the original UITabBarItem. 
     [v setAlpha:0.5]; 
     [v setBackgroundColor:[colorArray objectAtIndex:colorIndex]]; 
     // Add subview to UITabBarController view. 
     [[self tabBar] addSubview:v]; 
     // v is retained by the parent view, so release it. 
     [v release]; 
    } 
} 

, 당신은 새로운 질문을하기 전에 여기 스택 오버플로 답변을 검색하는 좋은 방법입니다 것을 알아야한다. 위의 링크를 사용하여 많은 진전을 이룰 수있었습니다. 지금까지 시도한 내용을 자세하게 설명하는 코드를 게시해야합니다. 사람들이 도움을 청하면 더 많은 도움을받을 수 있습니다.

나는 아직 초보자이기 때문에 코드를 게시했으며 귀하의 질문에 의해 제시된 도전을 즐겼습니다. 누구든지 내 코드에 대한 제안 사항이 있으면 의견을 말하십시오!

어쨌든이 도움이 되길 바랍니다.

+0

답장을 보내 주셔서 감사합니다. –

관련 문제