2011-12-10 5 views
0

私はUIButtonはこのように見えるようにしたい:UIButtonを削除ボタン(iphone/iPad)のように見えるようにするにはどうすればよいですか?

enter image description here

どのように私はこれを見て達成することができますか?組み込みの設定がありますか、それとも手動でPhotoshopで作成する必要がありますか?

+1

http://cocoawithlove.com/2008/09/drawing-gloss-gradients-in-coregraphics.html – 0x8badf00d

+0

[iPhone SDKで大きくて赤いUIButtonを作成するにはどうすればいいですか?] (http://stackoverflow.com/questions/1427818/how-can-i-create-a-big-red-uibutton-with-the-iphone-sdk) – Pang

答えて

1

カスタムのタイプのuibuttonを使用し、各状態の画像を提供します。

UIButton *myDeleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[myDeleteButton setImage:[UIImage imageNamed:@"ic_button_titlebar_delete.png"] forState:UIControlStateNormal]; 
[myDeleteButton setImage:[UIImage imageNamed:@"ic_button_titlebar_delete_on.png"] forState:UIControlStateSelected]; 

はい、PhotoShopや他のイメージングツールを使用する必要があります。

1

UIButtonの場合、これを実現するための設定はありません。グラデーションを使用して自分でコードを作成することも、ボタンの状態のカスタムイメージを作成することもできます。このボタンを取得する唯一の組み込みオプションは、UIActionSheet経由です。

3

1つのオプションは、この1つだけのように、背景に画像を使用することです:

red button gradient background image

on githubを発見されたGMButtonというクラスもあります。それぞれの状態にtitle、color、titleColorを設定することができます。 UIButton(UIButtonのサブクラス)の代わりに使用するだけです。それを使用すると、これらまたはこれらのようなボタンを作成することができます:あなたの[削除]ボタンについては

screenshot of buttons enter image description here

を、私はこれをしようとするだろう:

GMButton* button = [GMButton buttonWithFrame:CGRectMake(18,3,284,34)]; 

button.titleLabel.font = [UIFont systemFontOfSize:17]; 

[button setTitle:@"Delete" forState:UIControlStateNormal]; 
[button setColor:[UIColor redColor] forState:UIControlStateNormal]; 
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; 

これは、ボタンを作成するために、3つの層を使用しています。ベベルのCAGradientLayer、カラーのCALayer、ハイライトのCAGradientLayer。