0

私はiPad UIに取り組んでおり、そのUIのボタンには次の画像が必要です:

http://imgur.com/tVkP8wd

(PNGとして)。ボタンは次のように宣言されています。

CGRect newNoteButtonRect = CGRectMake(0, 0, 69, 43);                         
UIButton* newNoteButton = [[UIButton alloc] initWithFrame:newNoteButtonRect];
newNoteButton.imageView.contentMode = UIViewContentModeScaleToFill;
[newNoteButton setImage:self.fNewNoteIcon forState:UIControlStateNormal];

ここで、「fNewNoteIcon」は UIImage です。UI が表示されたとき、画像は小さくて押しつぶされており、私が何をしてもそれを変えることはほとんどできません。何か案は?

アイコンは次のように初期化されます。

self.fNewNoteIcon = [UIImage imageNamed:@"New_Note.png"];
4

2 に答える 2

0

その提供されたコードで、UIButtonタイプを指定していませんか? カスタム イメージを使用したボタンの作成

// Create image
self.fNewNoteIcon = [UIImage imageNamed:@"buttomImage.png"];

// Create rect for button. 0, 0 and size it from image
CGRect newNoteButtonRect = CGRectMake:(0, 0, _fNewNoteIcon.size.width, _fNewNoteIcon.size.height);

// Alloc and init UIButton with type
// Pass in image. Add to subview of view.
UIButton *newNoteButton = [UIButton buttonWithType: UIButtonTypeCustom];
[newNoteButton setImage: _fNewNoteIcon forState: UIControlStateNormal];
[self.view addSubview: newNoteButton];

コンパイルせずにこれをすべてSOに入力するので、確認してください。これにより、必要な画像が正しいサイズでUIButtonが表示されるはずです。

于 2013-08-29T22:46:18.123 に答える
0

そのため、PNG にアルファ チャネルがない場合、サイズの問題が発生するようです。PNG を Photoshop で開き、アルファ チャンネルを追加しました。画像は iPad で適切なサイズになりました。

于 2013-08-29T23:03:31.287 に答える