iOS 8 NavigationBar BackgroundImage
Z iOS 8 koncepcja tylko rozmiary iPhone i iPad wraz z Portret i krajobraz zmieniły się i dlatego ustawienie pasków nawigacji obraz tła nie działa tak samo. Obecnie używam następującego kodu:
UIImage *NavigationPortraitBackground = [[UIImage imageNamed:@"nav-image-portrait"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
UIImage *NavigationLandscapeBackground = [[UIImage imageNamed:@"nav-image-landscape"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:NavigationPortraitBackground forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:NavigationLandscapeBackground forBarMetrics:UIBarMetricsCompact];
Część bar metrics została wycofana z systemu iOS 8. Podczas uruchamiania mojej aplikacji po prostu powtarza obraz paska w poziomie, gdy na iPhone 6 lub 6 Plus. Zajrzałem do plasterków obrazu, ale nie sądzę, że to jest rozwiązanie ani jedno, ani drugie.
16
3 answers
Znalazłem rozwiązanie. Musiałem użyć metody resizableImageWithCapInsets: resizingMode: i ustawić resizingMode do UIImageResizingModeStretch, w przeciwnym razie obraz nadal kafelek w pasku nawigacyjnym.
Objective-C:
[[UIImage imageNamed:@"nav-image-portrait"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
Swift 3 / 4:
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "image")!.resizableImage(withCapInsets: UIEdgeInsets.zero, resizingMode: .stretch), for: .default)
73
Author: Chris,
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-10-11 15:34: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
2017-10-11 15:34:32
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"navbarimg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)] forBarMetrics:UIBarMetricsDefault];
Użyj powyższego kodu, który działa.I użyj małego rozmiaru obrazu (40*navigarbarheight)
40 to szerokość obrazu
4
Author: Suresh Thoutam,
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-26 05:46:58
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-26 05:46:58
Jest to przykładowy kod bardziej precyzyjny i dokładny, aby pasował do wszystkich rozmiarów ekranu . pomoże
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
[[UINavigationBar appearance] setBackgroundImage:[[UIImage imageNamed:@"header"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, screenWidth-50, 50)] forBarMetrics:UIBarMetricsDefault];
0
Author: Shahzaib Maqbool,
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-03-30 17:04:08
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-03-30 17:04:08