저는 앱 전체에서 "동작 색상"으로 초록색을 사용하고 있으며 일관성을 위해 내 UIActionSheets의 옵션도 초록색으로 표시하려고합니다. UIActionSheet 옵션의 색상을 파란색에서 녹색으로 변경하려면 어떻게합니까?iOS 7에서는 내 UIActionSheet의 옵션 색상을 어떻게 변경합니까?
10
A
답변
28
는 작업 시트 버튼 색상을 변경 UIActionSheet
의 willPresentActionSheet
위임 방법을 활용.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
{
for (UIView *subview in actionSheet.subviews) {
if ([subview isKindOfClass:[UIButton class]]) {
UIButton *button = (UIButton *)subview;
button.titleLabel.textColor = [UIColor greenColor];
}
}
}
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
당신은 AppDelegate에의 didFinishLaunchingWithOptions 방법에 짧은 기능을 사용하여 쉽게 응용 프로그램의 색조 색상을 변경할 수 있습니다.
[[UIView appearance] setTintColor:[UIColor redColor]];
은 당신을 도울 것입니다 희망 :
이 답변이 더 좋습니다. 대리자 메서드를 사용하여 더 간결하게 말할 필요가 없습니다. 또한 위의 대답은 취소 버튼의 색상을 변경하지 않습니다. – LazerLex
어떤 이유로 글꼴을 변경하려면 색상을 변경하기 전에 글꼴을 변경해야합니다. 그렇지 않으면 작동하지 않습니다. –
@BrenoGazzola : 어떻게됩니까? –