我有一个带有以下代码的工具栏;我想添加一个显示为“工具”的图像,名为“toolsIcon.png”。
下面是我的代码:
//BottomBar
UIToolbar *toolbar = [[UIToolbar alloc] init];
toolbar.frame = CGRectMake(0, self.view.frame.size.height - 44, self.view.frame.size.width, 44);
[self.view addSubview:toolbar];
[toolbar release];
//TOOLBAR ITEMS
//button 1
UIBarButtonItem *tools = [[UIBarButtonItem alloc] initWithTitle:@"Tools" style:UIBarButtonItemStyleBordered target:self action:@selector(createToolView)];
[tools setTag:0];
//add the buttons to the toolbar
NSArray *buttons = [NSArray arrayWithObjects: tools,nil];
[toolbar setItems: buttons animated:YES];
//memory management for buttons - don't waste!
[tools release];
最佳答案
您可以使用图像创建 UIBarButtonItem 并添加它
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithImage: yourImage style: UIBarButtonItemStyleBordered target: nil action: nil];
关于ios - 如何使用 Objective-C 在工具栏中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29594156/