UINavigationController ツールバーに追加するカスタム ビューを正確に制御したいと考えています。より具体的には..ツールバーのアイテムの上にUILableを表示したい。
私はtoolbarItems
いくつかの初期設定をしていUIBarButtonItems
ます。私が達成しようとしている効果は、プログラムでツールバーの高さを拡張しUILabel
、残りのボタンの上に表示することです..これは私が現在持っているものです:
-(void)expandToolBar:(NSString *)title {
UIToolbar* toolBar =self.navigationController.toolbar;
CGRect toolbarFrame = toolBar.frame;
[UIView animateWithDuration:0.25f delay:0
options:UIViewAnimationOptionLayoutSubviews animations:^{
// expand toolbar frame vertically
[toolBar setFrame:
CGRectMake(toolbarFrame.origin.x,
toolbarFrame.origin.y-15,
toolbarFrame.size.width,
toolbarFrame.size.height + 15)];
} completion:^(BOOL finished){
[UIView animateWithDuration:0.50f animations:^{
// some code here to move the existing toolbar items lower
// ie to make space for the label
UILabel* label = [[UILabel alloc] initWithFrame:labelFrame];
[label setBackgroundColor:[UIColor clearColor]];
label.text = title;
UIBarButtonItem *labelItem = [[UIBarButtonItem alloc]
initWithCustomView:label];
// add label to toolbar
NSMutableArray *newItems = [self.toolbarItems mutableCopy];
[newItems addObject:labelItem];
self.toolbarItems = newItems;
}];
}];
}
この結果、既存のすべてのボタンが押しつぶされ、ラベルが代わりになります。問題は、少しクリエイティブになりすぎてツールバーのサブビューを手動でいじり始めると、文書化されていない API の世界に迷い込み始めることです。これは Apple が容認しないものです。アイデア?