2

これが私が必要とするものです。

アプリの無料版と有料版があります。有料版が読み込まれると、UIToolBar に 3 つの UIBarButtons が必要になります。無料版が読み込まれると、4 つの UIBarButtons が必要になります。右端の barButton には青の色合いが必要ですが、残りはデフォルトの黒です。そして、それらの間の柔軟なスペースを想定して、それらを均等にします。IB を介してこれを実行しようとしましたが、適切な間隔で動作させることができないようです。ご覧のとおり、3 つのボタンを含む下部のツールバーは、ツールバーと等間隔に配置されていません。(プログラムでこれを行いたい)

ここに画像の説明を入力

ここに画像の説明を入力

#ifdef LITE_VERSION


#else

[buyButton removeFromSuperview];

#endif
4

4 に答える 4

10
UIToolbar* toolbar = [[UIToolbar alloc]
                  initWithFrame:CGRectMake(0, 0, 320, 45)];
[toolbar setBarStyle: UIBarStyleBlackOpaque];

// create an array for the buttons
NSMutableArray* BarbuttonsArray = [[NSMutableArray alloc] initWithCapacity:5];

// create a clearAll button
UIBarButtonItem * clearAllButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear All" 
                             style:UIBarButtonItemStylePlain
                             target:self
                             action:@selector(clearAllAction:)];

clearAllButton.style = UIBarButtonItemStyleBordered;
[BarbuttonsArray  addObject:clearAllButton];
[clearAllButton release];


 // create a calculate button
 UIBarButtonItem *calculateButton = [[UIBarButtonItem alloc]initWithTitle:@"Calculate" 
                             style:UIBarButtonItemStylePlain
                           target:self
                           action:@selector(calculateButton:)];
calculateButton.style = UIBarButtonItemStyleBordered;
[BarbuttonsArray  addObject:calculateButton];
[calculateButton release];


// create a settingButton
UIBarButtonItem *settingButton = [[UIBarButtonItem alloc]initWithTitle:@"Setting" 
                             style:UIBarButtonItemStylePlain
                             target:self
                             action:@selector(settingButton:)];
settingButton.style = UIBarButtonItemStyleBordered;
[BarbuttonsArray  addObject:settingButton];
[settingButton release];


 // create a buyNowButton

UIBarButtonItem *buyNowButton = [[UIBarButtonItem alloc]initWithTitle:@"Buy Now" 
                             style:UIBarButtonItemStylePlain
                          target:self
                          action:@selector(buyNowButton:)];
buyNowButton.style = UIBarButtonItemStyleBordered;
[BarbuttonsArray  addObject:buyNowButton];
[buyNowButton release];


 // put the BarbuttonsArray in the toolbar and release them
[toolbar setItems:BarbuttonsArray  animated:NO];
[BarbuttonsArray  release];

// place the toolbar into the navigation bar
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
[toolbar release];


//before using these lines of code you have to alloc and make the property of   UINavigationController in your appDelegate

これを使用してみてください

于 2012-06-15T07:09:09.137 に答える
0
IBOutlet UITabBarItem * item1;

tabbarItemこのように4つのアイテムを作成します...必要なときに必要なものを非表示にできるように、xibへのリンクを指定します...これがお役に立てば幸いです

于 2012-06-15T05:54:52.800 に答える
0

購入ボタンをデフォルトでツールバーに追加し、一意の値(たとえば、-1)でタグ付けすると、実行時に次のようにツールバーから削除できます。

#ifdef LITE_VERSION
    //Dont need to do anything, view is set up as lite version by default
#else

    NSArray *elements = toolBar.items;
    NSMutableArray *newElements = [[NSMutableArray alloc] initWithCapacity:[elements count]];

   for ( UIBarItem *item in elements )
   {
        if ( item.tag != -1 )
        {
            //Item is not the buy button, add it back to the array
            [newElements addObject:item];
        }
    }

    [toolBar setItems:newElements];

#endif

-1これは、表示されているビューに応じて、実行時にIBでタグ付けされたアイテムを特定のボタンに置​​き換えるためにアプリの1つですでに使用しているコードです。

于 2012-06-27T13:34:36.047 に答える
0

まず、ツールバーに購入ボタンを追加します。バインドして合成します。

if(AppPaid) { 
    NSMutableArray *items = [YourToolBar.items mutableCopy];
    [items removeObject:yourBuyButton];
    YourToolBar.items = items;
    [items release];
  }
于 2012-06-15T05:09:05.003 に答える