2010-11-22 19 views

答えて

34

のiOS 8(UIAlertController)

それはあなたがUIAlertControllerを使用している場合行うに超簡単です。 UIAlertControllerのビューで色合いの色を変更するだけです。

[alertController.view setTintColor:[UIColor red]; 

のiOS 7(UIActionSheet)

私は正常にこの簡単な方法を使って、テキストの色を変更します。

- (void) changeTextColorForUIActionSheet:(UIActionSheet*)actionSheet { 
    UIColor *tintColor = [UIColor redColor]; 

    NSArray *actionSheetButtons = actionSheet.subviews; 
    for (int i = 0; [actionSheetButtons count] > i; i++) { 
     UIView *view = (UIView*)[actionSheetButtons objectAtIndex:i]; 
     if([view isKindOfClass:[UIButton class]]){ 
      UIButton *btn = (UIButton*)view; 
      [btn setTitleColor:tintColor forState:UIControlStateNormal]; 

     } 
    } 
} 

[showInView]、すべてのボタンが、キャンセルボタンが着色される前に、あなたはそれを呼び出す場合は、

[actionSheet showInView]; 

を呼び出す後にこの を実行することを確認します。これが誰かを助けることを願って!

+0

これは選択された回答でなければなりません。よくやった。 – dclowd9901

+0

@ dclowd9901ありがとう! ;) – Rymnel

+2

ありがとうございます - iOS7でもうまくいきます。 – kmorris

1

残念ながら、ドキュメント化されていないAPIを使用しないと、UIActionSheetでボタンの色を変更する公式の方法はありません。 UIActionSheetコントロールをサブクラス化する場合、これをカスタマイズすることができます。

この例を参照してください:http://blog.corywiles.com/customizing-uiactionsheet-buttons

+0

を使用して、それを達成することができますか?どのサンプルコードも本当に役に立ちます。 – Abhinav

+0

上記のリンクを参照してください。 –

+0

ありがとうございました! – Abhinav

7

私はUIActionSheet内側のボタンのフォント、色とイメージをカスタマイズすることができます子クラスUICustomActionSheetを、作成しています。それは絶対にAppStoreのために安全である、あなたは次のリンク上で、このクラスのコードを見つけることができます。

https://github.com/gloomcore/UICustomActionSheet

がそれをお楽しみください!

+0

App Storeにとっては大丈夫ですか?とにかく結果は素晴らしいです! –

+0

はい、確かに、私はAppstore用のアプリで使っています。このクラスはプライベートメソッドを使用していないので、明らかです。 – Gloomcore

+0

それは素晴らしいです!投稿ありがとう! – yonix

1

私たちは背景イメージを使ってそれを行うことができます。私はそれが最も簡単な方法だと思う。

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Actionsheet" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
     [actionSheet addButtonWithTitle:@"Button 1"]; //Blue color 
     [actionSheet addButtonWithTitle:@"Button 2"]; 
     [actionSheet addButtonWithTitle:@"Cancel"]; 
     [actionSheet addButtonWithTitle:nil]; 
     [actionSheet setCancelButtonIndex:2]; 
     [actionSheet setDestructiveButtonIndex:1]; 
     [actionSheet showInView:self.view]; 
     UIButton *button = [[actionSheet subviews] objectAtIndex:1]; 
     UIImage *img = [button backgroundImageForState:UIControlStateHighlighted];//[UIImage imageNamed:@"alert_button.png"]; 
     [button setBackgroundImage:img forState:UIControlStateNormal]; 
0

あなたはこれをしなかったのあなたは簡単に次のコード

アップルUIActionSheetDelegateプロトコルのドキュメント

https://developer.apple.com/library/ios/documentation/uikit/reference/UIModalViewDelegate_Protocol/UIActionSheetDelegate/UIActionSheetDelegate.html

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet 
{ 
    for (UIView *_currentView in actionSheet.subviews) 
    { 
     if ([_currentView isKindOfClass:[UIButton class]]) 
     {  
      UIButton *button = (UIButton *)_currentView; 
      [button setTitleColor:YOUR_COLOR forState:UIControlStateNormal]; 
     } 
    } 
} 
関連する問題