我正在尝试更改后退按钮箭头

我目前正在使用以下内容来控制文本大小以及后退按钮上的文本颜色:
[[UIBarButtonItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont boldSystemFontOfSize:16.0f], UITextAttributeFont,
[UIColor darkGrayColor], UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(0.0, -1.0)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)
但如果我只想改变后退按钮的箭头颜色,我该怎么办?
Dis*_*Dev 438
要更改特定导航控制器的后退按钮V形颜色*:
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
Run Code Online (Sandbox Code Playgroud)
*如果您使用的应用程序具有多个导航控制器,并且您希望将此V形颜色应用于每个,您可能需要使用外观代理为每个导航控制器设置后退按钮V形符号,如下所示:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
在好的情况下,迅速(感谢Jay Mayu在评论中):
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
Run Code Online (Sandbox Code Playgroud)
Bar*_*uik 57
您必须设置整个应用程序的tintColor.
self.window.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
或者在Swift 3中:
self.window?.tintColor = UIColor.blue
Run Code Online (Sandbox Code Playgroud)
来源:iOS 7 UI过渡指南
小智 55
您可以使用该方法在整个应用程序导航栏上设置颜色
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions{
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
Run Code Online (Sandbox Code Playgroud)
小智 23
可以通过以下方式仅更改箭头的颜色(不是后退按钮标题的颜色):
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];
Run Code Online (Sandbox Code Playgroud)
导航栏包含_UINavigationBarBackIndicatorView类型的子视图(子视图数组中的最后一项),表示箭头.
Joh*_*ato 11
在初始化navigationController的rootViewController中,我将此代码放在viewDidAppear方法中:
//set back button color
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
//set back button arrow color
[self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
在iOS 6中,tintColor着色了导航栏,标签栏,工具栏,搜索栏和范围栏的背景.要在iOS 7中着色条形背景,请改用barTintColor属性.
小智 5
我不得不同时使用两者:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil]
forState:UIControlStateNormal];
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
并为我工作,谢谢大家!
UINavigationBar *nbar = self.navigationController.navigationBar;
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
//iOS 7
nbar.barTintColor = [UIColor blueColor]; // bar color
//or custom color
//[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
nbar.navigationBar.translucent = NO;
nbar.tintColor = [UIColor blueColor]; //bar button item color
} else {
//ios 4,5,6
nbar.tintColor = [UIColor whiteColor];
//or custom color
//[UIColor colorWithRed:19.0/255.0 green:86.0/255.0 blue:138.0/255.0 alpha:1];
}
Run Code Online (Sandbox Code Playgroud)
更新 Swift 3
navigationController?.navigationItem.rightBarButtonItem?.tintColor = UIColor.yellow
navigationController?.navigationBar.tintColor = UIColor.red
navigationController?.navigationBar.barTintColor = UIColor.gray
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blue]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
130459 次 |
| 最近记录: |