这个问题已被多次询问,但我尝试了所有解决方案,但没有一个解决了我的问题.
这是工具栏创建代码:
- (id)initWithBlogArticle:(BlogArticle *)theArticle
{
if (self = [super init])
{
CustomToolbar* tools = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 0, 90, 48.01)];
[tools setTintColor:[UIColor colorWithRed:0.62 green:0.70 blue:0.13 alpha:1.0]];
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
UIBarButtonItem* previousArticle = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRewind
target:self
action:@selector(displayPreviousArticle)];
[previousArticle setStyle:UIBarButtonItemStyleBordered];
[buttons addObject:previousArticle];
[previousArticle release];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
[buttons addObject:spacer];
[spacer release];
UIBarButtonItem *nextArticle = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFastForward
target:self
action:@selector(displayNextArticle)];
[nextArticle setStyle:UIBarButtonItemStyleBordered];
[buttons addObject:nextArticle];
[nextArticle release];
[tools setItems:buttons animated:NO];
[buttons release];
[[self navigationItem] …Run Code Online (Sandbox Code Playgroud) 我正在使用下面的一小段代码来更改我的导航栏标题应用程序的文本属性,它工作得很好.
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Cochin-BoldItalic" size:0.0], UITextAttributeFont,
nil]];
Run Code Online (Sandbox Code Playgroud)
但我希望能够轻松地为UIBarButtonItem文本执行此操作,但我无法理解它,因为它不会共享它出现的相同或类似的方法.任何帮助表示感谢,谢谢.
编辑:尝试此代码,不对文本进行任何更改:
[[UIBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Cochin-BoldItalic" size:12.0], UITextAttributeFont,
nil]
forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud) 在AppDelegate.m中使用它来为我的自定义NavBar:
UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"gradient_main"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
UIImage *barBackBtnImg = [[UIImage imageNamed:@"btn_nav_default.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barBackBtnImg forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
结果是:

如你所见,按钮似乎重复了.按钮尺寸为61x30.文本没有居中.如果文本较短(例如菜单),则按钮图像被剪切,如果文本较长,则按钮重复.具有较小图标(30x30)的按钮也存在类似问题.按钮显示正常,但我可以点击图像外的按钮:(
xcode objective-c uinavigationcontroller uibarbuttonitem ios
我正在尝试为我的UIToolBar添加一个自定义按钮(形状和颜色),但它的结果与它应该有很大不同.
什么按钮看起来像:

酒吧里的样子:

这是我用来添加它的代码:
UIImage *backButtonImage = [UIImage imageNamed:@"back-button.png"];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:backButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(backButtonTapped)];
[toolBarItems addObject:backButton];
Run Code Online (Sandbox Code Playgroud)
我到底错在了什么?
说我想要后退按钮@"Back"而不是标题UIViewController
这会奏效
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil];
Run Code Online (Sandbox Code Playgroud)
一个更明智的选择是这个
self.navigationItem.backBarButtonItem.title = @"Back";
Run Code Online (Sandbox Code Playgroud)
但事实并非如此.
为什么?
我在我的app delegate(iOS7)中有这个:
self.window.tintColor = [UIColor whiteColor];
但不知何故,uibarnavigationitem(系统默认添加图标)的颜色将自己设置为黑色,所有其他项目都是白色.虽然当我重置iPhone模拟器时,这个添加图标是白色的,但在重新运行应用程序时,它会变黑.
此人的色调颜色在属性检查器中设置为默认值.在代码中我没有选择让它变黑.
我在app委托中做错了什么?
我陷入一个小问题,
我使用此代码动态创建UIBarButtonItem ..
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(didSelectPopitDownFromNavBar:)];
self.navigationItem.rightBarButtonItem = rightButton;
Run Code Online (Sandbox Code Playgroud)
而选择器方法是这个..
-(IBAction)didSelectPopitDownFromNavBar:(id)sender event:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)
所以它点击了崩溃..我怎么能通过这个事件..?
iPhone的默认日历程序在导航栏中同时显示"<"和文本.
我想同时拥有图像和文本.
这是如何在Xcode中实现的?

我制作了一个标准的Master-Detail应用程序(使用Xcode模板).我修改了它,现在当我单击第一个表视图的一个单元格时,应用程序显示另一个表视图(这是详细信息,因为它被单击的单元格值过滤).在标准表视图中,我会在UINavigationBar上出现这种情况:
Edit Table title + (for adding new items)
我也需要UINavigationBar的默认后退按钮.有可能并允许这样做吗?图形上它会是这样的:
< Back Table title Edit +
你知道任何其他布局在顶部栏中显示3个按钮(后退 - 编辑 - 添加)加上标题吗?
很抱歉没有发布图片,提前致谢.
PS我想知道是否可以使用内置后退按钮和编辑按钮(我的意思是系统自动将其放入导航栏)进行操作.
我有一个带有UIBarButton的UIToolbar,其中包含一个包含图像的按钮(点击后图像会发生变化,所以我显然必须根据我的研究这样做).
虽然图像本身是白色的并且是png,但它显示为黑色(我希望它是白色的).我已将条形按钮项目上的色调颜色设置为白色,将按钮上的文本颜色设置为白色,并包含
button.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
在我的ViewDidLoad中.它仍然是黑色的.它应该始终是白色的,所以我不关心我是以编程方式还是通过InterfaceBuilder执行此操作.
uibarbuttonitem ×10
ios ×8
objective-c ×6
iphone ×2
ios7 ×1
swift ×1
uibutton ×1
uiimage ×1
uiimageview ×1
uitoolbar ×1
xcode ×1