2

UIButtonTypeCustom で UIButton を作成してみました。その後、次の方法を使用して外観を調整しました

[sendButton setImage:[UIImage imageNamed:@"sendButtonOff.png"] forState:UIControlStateNormal];
[sendButton setImage:[UIImage imageNamed:@"sendButtonOn.png"] forState:UIControlStateHighlighted];      
[sendButton setImage:[UIImage imageNamed:@"sendButtonDisabled.png"] forState:UIControlStateDisabled];

ただし、問題は、UIImages を状態に設定し始めると、setTitle が機能しなくなることです。setTitle は非 UIButtonTypeCustom でのみ機能すると思いますか? これは、テキストを画像自体に入れる (あまり堅牢ではない) か、これをサブクラス化してビューに UILabel を追加する必要があることを意味しますか? 大変な作業のようですね :( 何かアイデアはありますか?

4

1 に答える 1

10

タイトルを画像の上に表示したい場合は、これを試してください:

[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonOff.png"] forState:UIControlStateNormal];
[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonOn.png"] forState:UIControlStateHighlighted];      
[sendButton setBackgroundImage:[UIImage imageNamed:@"sendButtonDisabled.png"] forState:UIControlStateDisabled];
于 2009-07-14T02:21:34.437 に答える