IOS 7 pasek nawigacji tekst i kolor strzałek
Chcę ustawić tło dla paska nawigacyjnego na czarne , a wszystkie kolory wewnątrz niego na białe .
Więc użyłem tego kodu:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIColor whiteColor],
NSForegroundColorAttributeName,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
NSForegroundColorAttributeName,
[UIFont fontWithName:@"Arial-Bold" size:0.0],
NSFontAttributeName,
nil]];
Ale przycisk Wstecz kolor tekstu, Strzałki i przycisk paska nadal mają domyślny niebieski kolor.
Jak zmienić te kolory jak na obrazku poniżej?
10 answers
Zachowanie niektórych właściwości UINavigationBar
zmieniło się z iOS 7 . Możesz zobaczyć na obrazku pokazanym poniżej:
Dwa piękne linki, którymi chciałbym się z wami podzielić. Aby uzyskać więcej informacji, możesz przejść przez te linki:
- iOS 7 Przewodnik przejścia UI .
- Jak zaktualizować swoją aplikację na iOS 7.
Dokumentacja Apple dla barintcolor says:
Ten kolor jest domyślnie półprzezroczysta, chyba że ustawisz półprzezroczysta właściwość do NO.
Przykładowy Kod:
self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
[self.navigationController.navigationBar
setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
self.navigationController.navigationBar.translucent = NO;
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-25 14:11:43
//set bar color
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:85.0/255.0 green:143.0/255.0 blue:220.0/255.0 alpha:1.0]];
//optional, i don't want my bar to be translucent
[self.navigationController.navigationBar setTranslucent:NO];
//set title and title color
[self.navigationItem setTitle:@"Title"];
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];
//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]];
Mój pełny post na ten tutaj
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:48:03
Swift3, ios 10
Aby globalnie przypisać kolor, w AppDelegate didFinishLaunchingWithOptions
:
let textAttributes = [NSForegroundColorAttributeName:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
Swift 4, iOS 11
let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white]
UINavigationBar.appearance().titleTextAttributes = textAttributes
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-09-28 18:51:59
Odpowiedź Vina świetnie mi się sprawdziła. Oto to samo rozwiązanie dla programistów C# korzystających z Xamarin.iOS / MonoTouch:
var navigationBar = NavigationController.NavigationBar; //or another reference
navigationBar.BarTintColor = UIColor.Blue;
navigationBar.TintColor = UIColor.White;
navigationBar.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White });
navigationBar.Translucent = false;
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-07 14:44:56
[[UINavigationBar appearance] setTitleTextAttributes:@{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-01-31 15:25:35
Swift / iOS8
let textAttributes = NSMutableDictionary(capacity:1)
textAttributes.setObject(UIColor.whiteColor(), forKey: NSForegroundColorAttributeName)
navigationController?.navigationBar.titleTextAttributes = textAttributes
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-02-21 11:53:30
Aby zmienić kolor UINavigationBar
title należy użyć tego kodu:
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor]];
UITextAttributeTextColor
jest przestarzały w najnowszej wersji ios 7. Zamiast tego użyj NSForegroundColorAttributeName
.
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-01 11:51:50
Jeśli chcesz zmienić tytuł rozmiar tekstu i kolor tekstu musisz zmienić nsdictionary titleTextAttributes , dla 2 jego obiektów:
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:13.0],NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName,
nil];
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-08-04 10:33:05
Myślę, że poprzednie odpowiedzi są poprawne , to jest inny sposób na zrobienie tego samego. Dzielę się nim tutaj z innymi na wypadek, gdyby stał się dla kogoś przydatny. W ten sposób można zmienić kolor tekstu/tytułu dla paska nawigacyjnego w systemie iOS7:
UIColor *red = [UIColor colorWithRed:254.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:1.0];
NSMutableDictionary *navBarTextAttributes = [NSMutableDictionary dictionaryWithCapacity:1];
[navBarTextAttributes setObject:red forKey:NSForegroundColorAttributeName ];
self.navigationController.navigationBar.titleTextAttributes = navBarTextAttributes;
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-01-05 23:42:02
Wygląda na to, że Accessibility
sterowanie w iOS Settings
nadpisuje prawie wszystko, co próbujesz zrobić kolorowo przyciskom paska nawigacyjnego. Upewnij się, że masz wszystkie ustawienia domyślnych pozycji (Ustaw Zwiększ kontrast, pogrubiony tekst , kształty przycisków itp.), w przeciwnym razie nic się nie zmieni. Gdy to zrobiłem, cały kod zmiany koloru zaczął działać zgodnie z oczekiwaniami. Może nie musisz ich wszystkich wyłączać, ale nie dążyłem do tego dalej.
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-06-01 13:50:50