iOS 7 UIBarButton kolor strzałki przycisku Wstecz
Próbuję zmienić strzałkę przycisku Wstecz
Obecnie używam następujących do kontrolowania rozmiaru tekstu, a także koloru tekstu na przycisku Wstecz:
[[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];
Ale jeśli chcę zmienić tylko kolor strzałki dla przycisku wstecz, co mam zrobić?
17 answers
Aby zmienić kolor przycisku wstecz dla określonego kontrolera nawigacji*:
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
*Jeśli używasz aplikacji z więcej niż 1 kontrolerem nawigacyjnym i chcesz, aby ten kolor szewronu był stosowany do każdego kontrolera nawigacyjnego, możesz użyć proxy wyglądu, aby ustawić szewron przycisku wstecz dla każdego kontrolera Nawigacyjnego, w następujący sposób:
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
I na dobrą sprawę, w swift (dzięki Jay Mayu w komentarzach):
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-30 19:50:17
Musisz ustawić kolor tintColor całej aplikacji.
self.window.tintColor = [UIColor redColor];
Lub w Swift 3:
self.window?.tintColor = UIColor.blue
Source: iOS 7 UI Transition Guide
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-09-29 07:40:05
Możesz ustawić kolor na pasku nawigacji w całej aplikacji za pomocą metody
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions{
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-18 22:53:30
W ten sposób można zmienić tylko kolor strzałki (nie kolor tytułu przycisku Wstecz):
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor blackColor]];
Pasek nawigacji zawiera podgląd podrzędny typu _UINavigationBarBackIndicatorView (ostatnia Pozycja w tablicy podwidywań), który reprezentuje strzałkę.
Wynikiem jest pasek nawigacyjny z różnymi kolorami strzałki przycisku Wstecz i tytułu przycisku Wstecz
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-19 11:08:32
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-27 05:28:44
Wewnątrz rootViewController, który inicjuje navigationController, umieszczam ten kod w mojej metodzie 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]];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-10-03 13:49:26
W systemie iOS 6 kolor tintColor przyciemniał tło pasków nawigacji, pasków kart, pasków narzędzi, pasków wyszukiwania i pasków zakresu. Aby odcień tła paska w systemie iOS 7, użyj właściwości barTintColor.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-10 09:31:45
Możesz ustawić właściwość tintColor
Na przycisku (lub pozycji przycisku paska) lub widoku kontrolera widoku. Domyślnie właściwość dziedziczy tint z widoku nadrzędnego, aż do najwyższego poziomu UIWindow
aplikacji.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-08-22 15:22:34
Musiałem użyć obu:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTitleTextAttributes:[NSDictionary
dictionaryWithObjectsAndKeys:[UIColor whiteColor], UITextAttributeTextColor,nil]
forState:UIControlStateNormal];
[[self.navigationController.navigationBar.subviews lastObject] setTintColor:[UIColor whiteColor]];
I działa dla mnie, dziękuję wszystkim!
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-11-14 12:01:10
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];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-27 03:54:01
Update Swift 3
navigationController?.navigationItem.rightBarButtonItem?.tintColor = UIColor.yellow
navigationController?.navigationBar.tintColor = UIColor.red
navigationController?.navigationBar.barTintColor = UIColor.gray
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blue]
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-11-24 18:21:41
Aby zmienić kolor NavigationBar
możesz ustawić kolor tinty jak poniżej.
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-20 08:22:40
W przypadku, gdy robisz niestandardowy przycisk Wstecz na podstawie UIButton z obrazem strzałki, oto fragment podklasy. Za jego pomocą możesz utworzyć przycisk w kodzie lub po prostu przypisać klasę w Kreatorze interfejsu do dowolnego UIButton. Strzałka w tył zostanie dodana automatycznie i pokolorowana kolorem tekstu.
@interface UIImage (TintColor)
- (UIImage *)imageWithOverlayColor:(UIColor *)color;
@end
@implementation UIImage (TintColor)
- (UIImage *)imageWithOverlayColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, self.size.width, self.size.height);
if (UIGraphicsBeginImageContextWithOptions) {
CGFloat imageScale = 1.0f;
if ([self respondsToSelector:@selector(scale)])
imageScale = self.scale;
UIGraphicsBeginImageContextWithOptions(self.size, NO, imageScale);
}
else {
UIGraphicsBeginImageContext(self.size);
}
[self drawInRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
#import "iOS7backButton.h"
@implementation iOS7BackButton
-(void)awakeFromNib
{
[super awakeFromNib];
BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
UIImage *backBtnImage = [[UIImage imageNamed:@"backArrow"] imageWithOverlayColor:self.titleLabel.textColor];
[self setImage:backBtnImage forState:UIControlStateNormal];
[self setTitleEdgeInsets:UIEdgeInsetsMake(0, 5, 0, 0)];
[self setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
}
+ (UIButton*) buttonWithTitle:(NSString*)btnTitle andTintColor:(UIColor*)color {
BOOL is6=([[[UIDevice currentDevice] systemVersion] floatValue] <7);
UIButton *backBtn=[[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
UIImage *backBtnImage = [[UIImage imageNamed:@"backArrow"] imageWithOverlayColor:color];
[backBtn setImage:backBtnImage forState:UIControlStateNormal];
[backBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, is6?5:-5, 0, 0)];
[backBtn setImageEdgeInsets:UIEdgeInsetsMake(0, is6?0:-10, 0, 0)];
[backBtn setTitle:btnTitle forState:UIControlStateNormal];
[backBtn setTitleColor:color /*#007aff*/ forState:UIControlStateNormal];
return backBtn;
}
@end
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-18 10:22:48
Jeśli chcesz zmienić tylko strzałkę w tył, ale na całej aplikacji, Zrób to:
[[NSClassFromString(@"_UINavigationBarBackIndicatorView") appearance]
setTintColor:[UIColor colorWithHexString: @"#f00000"]];
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-09-24 12:11:42
W iOS 7 możesz umieścić następujący wiersz kodu w application:didFinishLaunchingWithOptions:
w pliku AppDelegate.m
:
[[UINavigationBar appearance] setTintColor:myColor];
Ustaw myColor
na kolor, który chcesz, aby przycisk Wstecz był w całej aplikacji. Nie ma potrzeby umieszczać go w każdym pliku.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-18 14:11:32
Swift 2.0: kolorowanie paska nawigacyjnego i przycisków
navigationController?.navigationBar.barTintColor = UIColor.blueColor()
navigationController?.navigationBar.tintColor = UIColor.whiteColor()
navigationController!.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-03-22 18:02:51
W swift 3, aby zmienić kolor strzałki przycisku tylnego UIBarButton
self.navigationController?.navigationBar.tintColor = UIColor.black
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-31 06:07:14