2013-10-06 1 views

답변

28

는 작업 시트 버튼 색상을 변경 UIActionSheetwillPresentActionSheet 위임 방법을 활용.

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    for (UIView *subview in actionSheet.subviews) { 
     if ([subview isKindOfClass:[UIButton class]]) { 
      UIButton *button = (UIButton *)subview; 
      button.titleLabel.textColor = [UIColor greenColor]; 
     } 
    } 
} 
+3

이 답변이 더 좋습니다. 대리자 메서드를 사용하여 더 간결하게 말할 필요가 없습니다. 또한 위의 대답은 취소 버튼의 색상을 변경하지 않습니다. – LazerLex

+0

어떤 이유로 글꼴을 변경하려면 색상을 변경하기 전에 글꼴을 변경해야합니다. 그렇지 않으면 작동하지 않습니다. –

+0

@BrenoGazzola : 어떻게됩니까? –

18

당신은 같은 것을 할 수있는 :이 많이 재사용 위하여려고하는 경우에

// Your code to instantiate the UIActionSheet 
UIActionSheet *actionSheet = [[UIActionSheet alloc] init]; 
// Configure actionSheet 

// Iterate through the sub views of the action sheet 
for (id actionSheetSubview in actionSheet.subviews) { 
    // Change the font color if the sub view is a UIButton 
    if ([actionSheetSubview isKindOfClass:[UIButton class]]) { 
     UIButton *button = (UIButton *)actionSheetSubview; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateNormal]; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateSelected]; 
     [button setTitleColor:[UIColor greenColor] forState:UIControlStateHighlighted]; 

    } 
} 

을, 나는 UIActionSheet를 서브 클래스 화해,이 코드를 사용하십시오.

+0

개인 API를 사용하여인가요? –

+0

아니요, UIActionSheet의 모든 하위보기에 액세스하고 단추를 찾습니다. – Tim

+1

탭하면 파란색으로 다시 바뀝니다. –

0

당신은 AppDelegate에의 didFinishLaunchingWithOptions 방법에 짧은 기능을 사용하여 쉽게 응용 프로그램의 색조 색상을 변경할 수 있습니다.

[[UIView appearance] setTintColor:[UIColor redColor]]; 

은 당신을 도울 것입니다 희망 :