2015-01-29 12 views
1

보기 컨트롤러가 모달로 표시 될 때 탐색 모음의 UILabel이 제대로 색조가 적용되지 않는 문제가 있습니다.보기 컨트롤러를 제시 할 때 UIBarButtonItem.customView의 하위보기 인 UILabel이 흐려지지 않음

UILabel은 내비게이션 컨트롤러의 rightBarButtonItem 인 UIBarButtonItem의 하위 뷰인 UIButton의 하위 뷰로서 탐색 모음에 있습니다. 계층 구조보기 :

 
rightBarButtonItem 
-UIBarButtonItem 
--UIButton <-- this is UIButtonTypeSystem, with a cart image. Tinting properly. 
---UILabel <-- this is the # of items in the cart. Not tinting. 

분명히 말하면 제시된 모달 중 레이블 색조를 제외한 모든 것이 올바르게 작동합니다. 보기 컨트롤러가 표시되기 전에 카트가 파란색으로 표시되고 카트 항목 수를 포함하는 레이블도 표시됩니다. 모달이 표시되면 카트 이미지가 어두워 지지만 레이블은 파란색으로 유지됩니다.

이미지를 게시하고 싶지만 미안하지만 평판이 충분하지 않습니다.

은 내가 시도하는 것 :

  • label.userInteractionEnabled = NO
  • 설정 가능한 모든 값으로 label.tintAdjustmentMode = UIViewTintAdjustmentModeDimmed (도움이되는 없음)
  • 서브 클래 싱있는 UIButton 및 설정하지 라벨
  • 의 농도 색상 설정 drawRect
  • 동안 # cart 항목 그리기보기 컨트롤러 프레젠테이션 중에 navigationItem.rightBarButtonItem.customView 계층 구조를 설정하고 tintAdjustmentMode를 수동으로 설정하십시오.

아무 것도 효과가 없습니다.

+(UIBarButtonItem*) getCartBarButtonItemWithDelegate:(id)delegate { 

    NSInteger cartItems = [[DataHandler sharedInstance]cartQuantity]; 

    NSString* num = [NSString stringWithFormat:@"%lu", (unsigned long) cartItems]; 
    NSString* cartImageToUse = @"cart_toolbar_button_icon"; 
    CGFloat fontSize = 11; 
    UILabel *label = nil; 

    if(cartItems > 0) { 
     if([num length] > 1) { 
      cartImageToUse = @"cartnumbered_toolbar_button2_icon"; 
      fontSize = 10; 
      label = [[UILabel alloc]initWithFrame:CGRectMake(7, -3, 16, 12)]; 
     } else { 
      cartImageToUse = @"cartnumbered_toolbar_button_icon"; 
      label = [[UILabel alloc]initWithFrame:CGRectMake(7.5, -3, 16, 12)]; 
     }   

     [label setFont:[UIFont systemFontOfSize:fontSize]]; 
     [label setText: num ]; 
     [label setTextAlignment:NSTextAlignmentCenter]; 
     [label setBackgroundColor:[UIColor clearColor]]; 
    } 

    // attempt at sub classing UIButton and drawing the number of items in the drawRect method 
    //CartButton *button = [CartButton buttonWithType:UIButtonTypeSystem]; 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; 
    [button setImage:[UIImage imageNamed: cartImageToUse] forState:UIControlStateNormal]; 
    [button addTarget:delegate action:@selector(handleCartTouch:)forControlEvents:UIControlEventTouchUpInside]; 
    [button setFrame:CGRectMake(0, 0, 25, 21)]; 

    if(label != nil) { 
     [label setTextColor: button.tintColor];      
     [button addSubview:label]; 
    } 

    UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithCustomView:button]; 
    [label release]; 
    return newBackButton; 
} 

어떤 아이디어 : 나는 여기

내가 UIBarButtonItem을 생성하고 코드입니다 ... 아이디어 나갈거야?

+0

'textColor '를 직접 변경하려고 했습니까? – dopcn

답변

0

모달 뷰 컨트롤러를 표시 할 때 레이블을 사용하지 않도록 설정하는 것이 가장 좋은 해결책입니다. 모달이 해제되면 도구 모음 메뉴 항목 (getCartBarButtonItemWithDelegate을 호출하여)을 다시 활성화 된 레이블로 바꿉니다.

나는이 방법을 시도해 본적이 없다. 이어야한다. 또한이 이어야합니다. iOS의 이후 버전이 링크 (및 비활성화 된 링크) 색상이 변경되면 링크 색상이 적절하게 표시되도록해야합니다.