5

何が間違っているのかわかりません。ファイル名は正しく、スタイルは無地に設定されています。しかし、私は私の画像のサイズの銀行の白い箱を手に入れました. UINavigationController を使用しています。

どうぞよろしくお願いいたします。

**参考までに、私はObjective Cに慣れていないので、私に負担をかけすぎないでください。;)

 UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc]
     initWithImage:[UIImage imageNamed:@"channel-guide-button.png"]
     style:UIBarButtonItemStylePlain
     target:self
     action:@selector(action:)];


self.toolbarItems = [NSArray arrayWithObjects:toolbarChannelGuideButton, nil];
[toolbarChannelGuideButton release];
4

3 に答える 3

9

白いマスクを作成した理由はUIToolBar、デフォルトではカラー画像を許可していないためです。これを実現する方法は、を作成してからそのイメージUIImageに割り当てることです。UIButton次に、をカスタムビューとしてUIBarButton使用initWithCustomViewしてを作成します。UIButton

コード:

     //Load the image   
     UIImage *buttonImage = [UIImage imageNamed:@"your-image.png"];

     //create the button and assign the image
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
     [button setImage:buttonImage forState:UIControlStateNormal];

     //sets the frame of the button to the size of the image
     button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);

     //creates a UIBarButtonItem with the button as a custom view
     UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];



     self.toolbarItems = [NSArray arrayWithObjects:customBarItem, nil];
     [customBarItem release];
于 2010-10-27T01:52:59.057 に答える
-1

channel-guide-button.pngはプロジェクトに属していますか?

あなたはこれを次のように分解することができます:

UIImage *image = [UIImage imageNamed:@"channel-guide-button.png"];
NSLog(@" image = %p", image);
UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc]
     initWithImage:image
     style:UIBarButtonItemStylePlain
     target:self
     action:@selector(action:)];

または、プロジェクトを確認してください;-)

于 2010-10-27T00:54:23.943 に答える