【发布时间】:2012-05-21 21:35:01
【问题描述】:
我正在尝试以编程方式将UILabel 添加到我的UIToolBar 中,但它似乎没有出现。这就是我对代码所做的事情。
- (void) viewWillAppear:(BOOL)animated
{
// Create custom toolbar at top of screen under navigation controller
[matchingSeriesInfoToolBar setFrame:CGRectMake(0, 60, 320, 30)];
matchingSeriesInfoToolBar = [UIToolbar new];
[matchingSeriesInfoToolBar sizeToFit];
CGFloat toolbarHeight = 30;
CGRect mainViewBounds = [[UIScreen mainScreen] applicationFrame];
[matchingSeriesInfoToolBar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds), 0, CGRectGetWidth(mainViewBounds), toolbarHeight)];
matchingSeriesInfoToolBar.tintColor = [UIColor darkGrayColor];
[self.view addSubview:matchingSeriesInfoToolBar];
// Create size of uitableview (to fit toolbar.
[matchingSeriesTableView setFrame:CGRectMake(0, 30, self.view.frame.size.width, self.view.frame.size.height - 30)];
[self.view addSubview:matchingSeriesTableView];
// Ad UILabel to the toolbar
UIBarButtonItem *textFieldItem = [[UIBarButtonItem alloc] initWithCustomView:manufSelectionLabel];
matchingSeriesInfoToolBar.items = [NSArray arrayWithObject:textFieldItem];
manufSelectionLabel.text = @"Hello World!";
[super viewWillAppear:animated];
}
几乎我已经创建了一个自定义工具栏,我已经从屏幕底部更改了通常的位置,出现在UINavigationController 下,这也像这样添加到视图中,因此它在视图中正确动画过渡..
之后我创建了 tableview 的大小,以便它出现在自定义工具栏之后..
然后从那里我尝试将UILabel 添加到工具栏.. 但由于某种原因它无法正常工作。
任何帮助将不胜感激。
【问题讨论】:
-
仅供参考:此代码应位于
viewDidLoad或每次您的视图出现时(可能包括在另一个视图上按下后退按钮!)您将获得另一个工具栏等:) -
哦,是的!抱歉,我之前一直在制作导航工具栏动画,因此曾尝试在此工作..但我从未从那里获取代码..我非常努力地试图让这个工具栏运行,但我没有看到。感谢您的提醒
标签: iphone ios uitableview uilabel uitoolbar