1

私の問題は次のとおりです。ツールバーのアイテムの座標を知りたいので、そこにデータをポップできます。これらのbarbuttonitemsは、フレームのプロパティを表示することはありません。
解決策はありますか?

4

3 に答える 3

0

間隔を空けたい場合に使用できます。

UIBarButtonItem *fixedLeftSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];

//カスタムビューを追加するため

UIButton *webButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [webButton setFrame:CGRectMake(0, 0, 50, 40)];
        [webButton setImage:[UIImage imageNamed:@\"webIcon.jpg\"] forState:UIControlStateNormal];
        [webButton addTarget:self action:@selector(goToWebPage) forControlEvents:UIControlEventTouchDown];


        UIBarButtonItem *webpageBtn = [[UIBarButtonItem alloc]initWithCustomView:webButton];
        [webpageBtn setTarget:self];
        [webpageBtn setAction:@selector(goToWebPage)];

    [toolbar setItems:[NSArray arrayWithObjects: webpageBtn,fixedLeftSpace,webpageBtn, nil]];

リンクも参照してください。

于 2012-12-05T10:51:08.603 に答える
0
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 210, 44)];
 UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
 NSMutableArray* buttons = [[NSMutableArray alloc] initWithObjects:bt1,space,bt2,space,bt3, nil];

    [tools setItems:buttons animated:YES];

    UIBarButtonItem *toolsBtn = [[UIBarButtonItem alloc]initWithCustomView:tools];

    self.navigationItem.rightBarButtonItem = toolsBtn;
于 2012-12-05T10:57:18.530 に答える
0

xib ファイルからツールバーを作成する場合、ツールバーに複数のバー ボタンがある場合は、ボタンの前後に複数の「フレキシブル スペース バー ボタン項目」を追加して、必要な間隔が得られるようにする必要があります。UIToolbar を動的に作成している場合は、柔軟なボタンを動的に追加する必要があります。

于 2012-12-05T11:00:30.383 に答える