-1

インターフェイスビルダーに UIToolbar があります。IBOutlets を使用して UIToolbar に接続しました。initWithCoder および viewDidLoad イベントのコードで、UIToolbar の bounds.size.width プロパティにアクセスしようとすると、0 と表示されます。最終的に、UILabel を UIToolbar の中央に配置したいと考えています。

4

1 に答える 1

1

UIBarButtomItem次のように使用する必要があります。

UIBarButtonItem *flexible1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:@"Your Label String" style:UIBarButtonItemStylePlain target:nil action:nil];

UIBarButtonItem *flexible2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

[toolBar setItems:[NSArray arrayWithObjects:flexible1, titleButton, flexible2, nil]];
于 2013-04-11T19:39:21.413 に答える