ios - 如何使用 Objective-C 在工具栏中显示图像

标签 ios objective-c uitoolbar theos

我有一个带有以下代码的工具栏;我想添加一个显示为“工具”的图像,名为“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/

相关文章:

objective-c - xcode 中的导航栏或工具栏问题

ios - 具有减少的 alpha 的 UIToolBar,希望 UIBarButtonItem 具有 alpha 1

iphone - 如何在 iPhone 中将标签拖放到 UIToolbarItem 上

ios - 如何计算有机形状的面积?

ios - 如何验证多维 NSArray 结构?

ios - 更改 UIControlState.Highlighted 上的 UIButton backgroundColor?

ios - 向 UIAlertView 添加声音的正确方法

objective-c - 如何更改 block 中的int值?

ios - 更改 UIToolbar 项目导致工具栏变为空白

ios - 尝试从动态 UITableViewCell 执行 popover segue 时出现编译错误