5

私はコードを使用しています:

  {
        randomstatus=0;
        msg=[[NSString alloc]initWithFormat:@"Good job, do you want to continue?"];
        UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:msg delegate:self cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes" otherButtonTitles:nil];
        [actionSheet showInView:self.view];
        [actionSheet release];
        [msg release];
    }   

コードを変更したくありませんが、「destructiveButton」を赤ではなく緑にする必要があります。これは可能ですか、それとも別のボタンを使用する必要がありますか?

4

2 に答える 2

3

ボタンの外観を変更する「標準的な」方法はありません。使用する方法は基本的にハックであり、Apple が UIActionSheet コンポーネントを変更すると、将来壊れる可能性があります。また、App-Store の神々を動揺させた場合、アプリが拒否される可能性もあります。

これを達成するための最も将来性のある方法は、独自のアクション シート クラスを最初から作成することです。つまり、UIActionSheet をサブクラス化しないことです (これは将来壊れる可能性があるため)。これはいくつかのハックよりも前もって行う作業が少し多いかもしれませんが、得られる余分な柔軟性は将来的に役立ちます。

これはそれほど難しくないはずです。アクション シートの背景となるビューが必要になります。これは、標準の UIActionSheet のスクリーンショットを撮り、フォト ショッピングを行うことで取得できます。次に、カスタム ボタンをサブビューとして追加します。ビューを表示するための少しのアニメーションで完了です。

UIActionSheet が実行するすべてのメソッドをクラスに実装し、UIActionSHeetDelegate が期待するメソッドを起動することを目指します。このようにして、他の方法ではネイティブの UIActionSheet を使用する場所に置き換えることができます

于 2010-03-21T22:25:59.070 に答える
2

Unfortunately there aren't any officially provided methods for customizing UIActionSheet buttons.

However you can access the subviews of the UIActionSheet (which could break in a future iPhone OS update), or add a new view with a button that covers the original destructive action button (once again, this may break).

While not directly related to changing the color of a button on a UIActionSheet, this previous question: iPhone Disabling UIActionSheet buttons demonstrates a few ways you could add custom views to a UIActionSheet.

于 2010-03-21T22:14:31.057 に答える