【问题标题】:navcontroller - Setting up Navigation Item as imagenavcontroller - 将导航项设置为图像
【发布时间】:2012-10-09 21:54:10
【问题描述】:
我想将导航控制器栏按钮项设置为图像。
我已阅读以下内容 - Add image to a navigationItem's title
我了解如何将其设置为图像。我实际上希望将其设置为设置 cog,在条形按钮项目中(如 cog 图标)。我以前在其他应用程序中看到过这种情况,我想知道是否有默认样式来为此初始化,或者通常是否通过上述图像路由实现。
如果上面是这样,有谁知道这种(某种)默认图像样式图标在哪里可用,或者我需要制作一个吗?
【问题讨论】:
标签:
ios
ios5
uinavigationcontroller
uinavigationbar
uinavigationitem
【解决方案1】:
您是否尝试过使用UIBarButtonItem 的initWithCustomView 选项?示例代码如下所示。
UIBarButtonItem *aButton = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"settings.png"]]];
另一种方法是,
UIBarButtonItem *aButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"settings.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(buttonTapped)];
【解决方案2】:
如果你使用storyboard,可以直接:
- 在导航栏中拖动
Button 而不是Bar Button Item。它会自动为您创建一个Button Bar Item,其中包含一个Button。
- 输入
Button Bar Item 的标题
- 为
Button 设置一个Custom 类型的图像。
它应该可以工作。