添加一个UILabel到UIToolbar

问题描述 投票:95回答:8

我想一个标签添加到我的工具栏。巴顿的伟大工程,但是当我添加标签对象,它崩溃。有任何想法吗?

UIBarButtonItem *setDateRangeButton = [[UIBarButtonItem alloc] initWithTitle:@"Set date range"
                                                                       style:UIBarButtonItemStyleBordered
                                                                      target:self
                                                                      action:@selector(setDateRangeClicked:)];

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(5, 5, 20, 20)];
label.text = @"test";

[toolbar setItems:[NSArray arrayWithObjects:setDateRangeButton,label, nil]];

// Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];

// Reload the table view
[self.tableView reloadData];
ios iphone uibarbuttonitem
8个回答
© www.soinside.com 2019 - 2024. All rights reserved.