-1

我在界面生成器中有一个 UIToolbar。我使用 IBOutlets 与 UIToolbar 建立了连接。在我的 initWithCoder 和 viewDidLoad 事件的代码中,我尝试访问 UIToolbar 的 bounds.size.width 属性,它显示为 0。最终,我想在 UIToolbar 内居中放置一个 UILabel。

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 回答