Iphone 更改导航栏按钮文本颜色
我正在创建自定义视图以生成导航栏项Iphone 更改导航栏按钮文本颜色,iphone,ipad,uinavigationcontroller,Iphone,Ipad,Uinavigationcontroller,我正在创建自定义视图以生成导航栏项 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization UIView *backButtonVie
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,35)];
UIButton *myBackButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
[myBackButton setFrame:CGRectMake(0,0,70,35)];
myBackButton.titleLabel.text = @"Back";
myBackButton.backgroundColor = [UIColor yellowColor];
myBackButton.titleLabel.textAlignment = UITextAlignmentCenter;
myBackButton.titleLabel.textColor = [UIColor blackColor];
[myBackButton setEnabled:YES];
[myBackButton addTarget:self.navigationController action:@selector(moveBack:) forControlEvents:UIControlEventTouchUpInside];
[backButtonView addSubview:myBackButton];
[myBackButton release];
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
self.navigationItem.leftBarButtonItem = backButton;
[backButtonView release];
[backButton release];
CGRect frame = CGRectMake(300, 0, 400, 35);
UILabel *label = [[[UILabel alloc] initWithFrame:frame] autorelease];
label.backgroundColor = [UIColor yellowColor];
label.font = [UIFont boldSystemFontOfSize:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.text = @"Order booking";
self.navigationItem.titleView = label;
}
return self;
}
有了这个,我得到了以下输出:
我希望工具栏按钮与导航栏具有相同的背景颜色,其文本为黑色。我已经尝试过使用UINavigationController委托以任何一种方式进行此操作,但没有成功。
我需要做哪些更改?阅读5.0文档。在WWDC'11会议上,我们讨论了一种新的、更简单的方法。(第114课时-自定义UIKit控件的外观)。阅读5.0文档。在WWDC'11会议上,我们讨论了一种新的、更简单的方法。(第114课时-自定义UIKit控件的外观)。此处介绍如何更改UIBAButtonim的文本标签颜色(例如,变为黑色)(默认情况下,文本标签为白色): 特别是当您选择按钮的浅色色调(背景色)时:
self.myBarButton.tintColor = [UIColor yellowColor];
不要忘记,您可能还需要更改文本标签的阴影颜色:
(在更改文本标签颜色之前,应先放置代码,以免阴影重新绘制在文本标签颜色的顶部!)
以下是如何更改UIBarButtonItem的文本标签颜色(例如,更改为黑色)(默认情况下,文本标签为白色): 特别是当您选择按钮的浅色色调(背景色)时:
self.myBarButton.tintColor = [UIColor yellowColor];
不要忘记,您可能还需要更改文本标签的阴影颜色:
(在更改文本标签颜色之前,应先放置代码,以免阴影重新绘制在文本标签颜色的顶部!)
我可以在哪里下载或查看5.0文档。我可以在xcode 3中安装它吗?请帮助我。我可以在哪里下载WWDC的所有新示例代码。谢谢。我正在等待您的早期答复。您可以找到所有会话。会话114称为“自定义UIKit控件的外观”。您需要使用Apple ID登录才能看到它。要为iOS 5 SDK编码,您需要Xcode 4.2。目前,会议中有一些示例代码,但到目前为止,它们仅对WWDC与会者可用。我猜新iOS5API的文档还没有完成,也没有发布。不过,这些会话确实会引导您浏览大量代码。我可以在哪里下载或查看5.0文档。我可以在xcode 3中安装此程序吗?请帮助我。我可以在哪里下载WWDC的所有新示例代码。谢谢。我正在等待您的早期答复。您可以找到所有会话。会话114称为“自定义UIKit控件的外观”。您需要使用Apple ID登录才能看到它。要为iOS 5 SDK编码,您需要Xcode 4.2。目前,会议中有一些示例代码,但到目前为止,它们仅对WWDC与会者可用。我猜新iOS5API的文档还没有完成,也没有发布。不过,这些会话确实会引导您浏览大量的代码。
uitexttributetextcolor
在swift4.0中更改为NSForegroundColorAttributeName
,在swift4.0中将是nsAttributeStringKey。在swift4.0中,将是uitexttributetextcolor
更改为NSForegroundColorAttributeName
nsAttribute StringKey.foregroundColor
[self.fullVersionViewButton setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor grayColor] forKey:UITextAttributeTextShadowColor] forState:UIControlStateNormal];