puede pantalla mensajes letra hora como color cambio cambiar ios ios7 uicolor ios-statusbar

pantalla - ¿Cómo cambiar el color de fondo y el color de texto de la barra de estado en iOS 7?



mi iphone cambio de color la pantalla (17)

Mi aplicación actual se ejecuta en iOS 5 y 6.

La barra de navegación tiene un color naranja y la barra de estado tiene un color de fondo negro con un color de texto blanco. Sin embargo, cuando ejecuto la misma aplicación en iOS 7, observo que la barra de estado se ve transparente con el mismo color de fondo anaranjado que la barra de navegación y el color del texto de la barra de estado es negro.

Debido a esto, no puedo diferenciar entre la barra de estado y la barra de navegación.

¿Cómo hago para que la barra de estado se vea igual que en iOS 5 y 6, es decir, con el color de fondo negro y el color de texto blanco? ¿Cómo puedo hacer esto programáticamente?


1) establece UIViewControllerBasedStatusBarAppearance en YES en el plist

2) en viewDidLoad hacer un [self setNeedsStatusBarAppearanceUpdate];

3) agregue el siguiente método:

-(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; }

ACTUALIZAR:
también revise developers-guide-to-the-ios-7-status-bar


Al manejar el color de fondo de la barra de estado en iOS 7, hay 2 casos

Caso 1: vista con barra de navegación

En este caso, use el siguiente código en su método viewDidLoad

UIApplication *app = [UIApplication sharedApplication]; CGFloat statusBarHeight = app.statusBarFrame.size.height; UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, -statusBarHeight, [UIScreen mainScreen].bounds.size.width, statusBarHeight)]; statusBarView.backgroundColor = [UIColor yellowColor]; [self.navigationController.navigationBar addSubview:statusBarView];

Caso 2: vista sin barra de navegación

En este caso, use el siguiente código en su método viewDidLoad

UIApplication *app = [UIApplication sharedApplication]; CGFloat statusBarHeight = app.statusBarFrame.size.height; UIView *statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, statusBarHeight)]; statusBarView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:statusBarView];

Enlace de origen http://code-ios.blogspot.in/2014/08/how-to-change-background-color-of.html


Aquí hay una solución total, copiar y pegar, con una

explicación absolutamente correcta

de cada problema involucrado.

¡Gracias a Warif Akhand Rishi!

para obtener el sorprendente descubrimiento sobre keyPath statusBarWindow.statusBar . Buena persona

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // handle the iOS bar! // >>>>>NOTE<<<<< // >>>>>NOTE<<<<< // >>>>>NOTE<<<<< // "Status Bar Style" refers to the >>>>>color of the TEXT<<<<<< of the Apple status bar, // it does NOT refer to the background color of the bar. This causes a lot of confusion. // >>>>>NOTE<<<<< // >>>>>NOTE<<<<< // >>>>>NOTE<<<<< // our app is white, so we want the Apple bar to be white (with, obviously, black writing) // make the ultimate window of OUR app actually start only BELOW Apple''s bar.... // so, in storyboard, never think about the issue. design to the full height in storyboard. let h = UIApplication.shared.statusBarFrame.size.height let f = self.window?.frame self.window?.frame = CGRect(x: 0, y: h, width: f!.size.width, height: f!.size.height - h) // next, in your plist be sure to have this: you almost always want this anyway: // <key>UIViewControllerBasedStatusBarAppearance</key> // <false/> // next - very simply in the app Target, select "Status Bar Style" to Default. // Do nothing in the plist regarding "Status Bar Style" - in modern Xcode, setting // the "Status Bar Style" toggle simply sets the plist for you. // finally, method A: // set the bg of the Apple bar to white. Technique courtesy Warif Akhand Rishi. // note: self.window?.clipsToBounds = true-or-false, makes no difference in method A. if let sb = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView { sb.backgroundColor = UIColor.white // if you prefer a light gray under there... //sb.backgroundColor = UIColor(hue: 0, saturation: 0, brightness: 0.9, alpha: 1) } /* // if you prefer or if necessary, method B: // explicitly actually add a background, in our app, to sit behind the apple bar.... self.window?.clipsToBounds = false // MUST be false if you use this approach let whiteness = UIView() whiteness.frame = CGRect(x: 0, y: -h, width: f!.size.width, height: h) whiteness.backgroundColor = UIColor.green self.window!.addSubview(whiteness) */ return true }


Cambiar el color de fondo de la barra de estado: Swift:

let proxyViewForStatusBar : UIView = UIView(frame: CGRectMake(0, 0,self.view.frame.size.width, 20)) proxyViewForStatusBar.backgroundColor=UIColor.whiteColor() self.view.addSubview(proxyViewForStatusBar)


En el caso de swift 2.0 en iOS 9

Coloque lo siguiente en el delegado de la aplicación, en didFinishLaunchingWithOptions:

let view: UIView = UIView.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, 20)) view.backgroundColor = UIColor.blackColor() //The colour you want to set view.alpha = 0.1 //This and the line above is set like this just if you want the status bar a darker shade of the colour you already have behind it. self.window!.rootViewController!.view.addSubview(view)


En iOS 7, la barra de estado no tiene fondo, por lo tanto, si coloca una vista negra de 20 píxeles de alto obtendrá el mismo resultado que iOS 6.

También es posible que desee leer la Guía de transición de la interfaz de usuario de iOS 7 para obtener más información sobre el tema.


Escribe esto en tu Método ViewDidLoad:

if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) { self.edgesForExtendedLayout=UIRectEdgeNone; self.extendedLayoutIncludesOpaqueBars=NO; self.automaticallyAdjustsScrollViewInsets=NO; }

Me arregló el color de la barra de estado y otras extraviaciones de UI también en cierta medida.


La solución iTroid23 funcionó para mí. Extrañé la solución Swift. Entonces quizás esto sea útil:

1) En mi plist tuve que agregar esto:

<key>UIViewControllerBasedStatusBarAppearance</key> <true/>

2) No necesité llamar a "setNeedsStatusBarAppearanceUpdate".

3) In swift tuve que agregar esto a mi UIViewController:

override func preferredStatusBarStyle() -> UIStatusBarStyle { return UIStatusBarStyle.LightContent }


Logré personalizar bastante el color de StatusBar y AppDelegate.cs archivo AppDelegate.cs en el método:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)

siguiente código:

UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView; if (statusBar!=null && statusBar.RespondsToSelector(new Selector("setBackgroundColor:"))) { statusBar.BackgroundColor = Color.FromHex(RedColorHex).ToUIColor(); }

Entonces obtienes algo como esto:

Enlace: https://jorgearamirez.wordpress.com/2016/07/18/lesson-x-effects-for-the-status-bar/


Para el color de la barra: proporciona una imagen de fondo personalizada para la barra.

Para el color del texto: use la información en Acerca del manejo de texto en iOS


Por favor prueba esto Utilice este código en su clase de la clase appdelegate "didFinishLaunchingWithOptions"

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; [application setStatusBarHidden:NO]; UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { statusBar.backgroundColor = [UIColor blackColor]; }


Puede establecer el color de fondo para la barra de estado durante el inicio de la aplicación o durante viewDidLoad de su controlador de vista.

extension UIApplication { var statusBarView: UIView? { return value(forKey: "statusBar") as? UIView } } // Set upon application launch, if you''ve application based status bar class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { UIApplication.shared.statusBarView?.backgroundColor = UIColor.red return true } } or // Set it from your view controller if you''ve view controller based statusbar class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() UIApplication.shared.statusBarView?.backgroundColor = UIColor.red } }



Aquí está el resultado:


Aquí están las Pautas / Instrucciones de Apple sobre el cambio de la barra de estado. Solo Dark & ​​light (while & black) están permitidos en la barra de estado.

Aquí está - Cómo cambiar el estilo de la barra de estado:

Si desea establecer el estilo de la barra de estado, nivel de aplicación, configure UIViewControllerBasedStatusBarAppearance en NO en su archivo `.plist ''.

si desea establecer el estilo de la barra de estado, en el nivel de control de la vista, siga estos pasos:

  1. Establezca UIViewControllerBasedStatusBarAppearance en YES en el archivo .plist , si necesita establecer el estilo de barra de estado solo en el nivel UIViewController.
  2. En la función addDidLoad add - setNeedsStatusBarAppearanceUpdate

  3. anular preferredStatusBarStyle en su controlador de vista.

-

override func viewDidLoad() { super.viewDidLoad() self.setNeedsStatusBarAppearanceUpdate() } override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }


Si está utilizando un UINavigationController , puede usar una extensión como esta:

extension UINavigationController { private struct AssociatedKeys { static var navigationBarBackgroundViewName = "NavigationBarBackground" } var navigationBarBackgroundView: UIView? { get { return objc_getAssociatedObject(self, &AssociatedKeys.navigationBarBackgroundViewName) as? UIView } set(newValue) { objc_setAssociatedObject(self, &AssociatedKeys.navigationBarBackgroundViewName, newValue, .OBJC_ASSOCIATION_RETAIN) } } func setNavigationBar(hidden isHidden: Bool, animated: Bool = false) { if animated { UIView.animate(withDuration: 0.3) { self.navigationBarBackgroundView?.isHidden = isHidden } } else { navigationBarBackgroundView?.isHidden = isHidden } } func setNavigationBarBackground(color: UIColor, includingStatusBar: Bool = true, animated: Bool = false) { navigationBarBackgroundView?.backgroundColor = UIColor.clear navigationBar.backgroundColor = UIColor.clear navigationBar.barTintColor = UIColor.clear let setupOperation = { if includingStatusBar { self.navigationBarBackgroundView?.isHidden = false if self.navigationBarBackgroundView == nil { self.setupBackgroundView() } self.navigationBarBackgroundView?.backgroundColor = color } else { self.navigationBarBackgroundView?.isHidden = true self.navigationBar.backgroundColor = color } } if animated { UIView.animate(withDuration: 0.3) { setupOperation() } } else { setupOperation() } } private func setupBackgroundView() { var frame = navigationBar.frame frame.origin.y = 0 frame.size.height = 64 navigationBarBackgroundView = UIView(frame: frame) navigationBarBackgroundView?.translatesAutoresizingMaskIntoConstraints = true navigationBarBackgroundView?.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin] navigationBarBackgroundView?.isUserInteractionEnabled = false view.insertSubview(navigationBarBackgroundView!, aboveSubview: navigationBar) } }

Básicamente, hace que el fondo de la barra de navegación sea transparente y utiliza otra UIView como fondo. Puede llamar al método setNavigationBarBackground de su controlador de navegación para establecer el color de fondo de la barra de navegación junto con la barra de estado.

Tenga en cuenta que debe utilizar el setNavigationBar(hidden: Bool, animated: Bool) en la extensión cuando desee ocultar la barra de navegación; de lo contrario, la vista que se usó como fondo seguirá estando visible.


Solo para agregar a la respuesta de Shahid, puedes contabilizar los cambios de orientación o diferentes dispositivos que usan esto (iOS7 +):

- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... //Create the background UIView* statusBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, 20)]; statusBg.backgroundColor = [UIColor colorWithWhite:1 alpha:.7]; //Add the view behind the status bar [self.window.rootViewController.view addSubview:statusBg]; //set the constraints to auto-resize statusBg.translatesAutoresizingMaskIntoConstraints = NO; [statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0]]; [statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0]]; [statusBg.superview addConstraint:[NSLayoutConstraint constraintWithItem:statusBg attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:statusBg.superview attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0]]; [statusBg.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[statusBg(==20)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(statusBg)]]; [statusBg.superview setNeedsUpdateConstraints]; ... }


para el fondo puede agregar fácilmente una vista, como en el ejemplo:

UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,320, 20)]; view.backgroundColor=[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.1]; [navbar addSubview:view];

donde "navbar" es un UINavigationBar.

¡Espero que pueda ayudarte!


info.plist su aplicación info.plist

1) Establecer la View controller-based status bar appearance en NO
2) Establecer el Status bar style en UIStatusBarStyleLightContent

Luego, vaya a su delegado de la aplicación y pegue el siguiente código donde configure RootViewController de su Windows.

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 20)]; view.backgroundColor=[UIColor blackColor]; [self.window.rootViewController.view addSubview:view]; }

Espero eso ayude.


Tenía que intentar buscar otras formas. Lo cual no implica addSubview en la ventana. Porque me estoy moviendo por la ventana cuando se presenta el teclado.

C objetivo

- (void)setStatusBarBackgroundColor:(UIColor *)color { UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@"statusBarWindow"] valueForKey:@"statusBar"]; if ([statusBar respondsToSelector:@selector(setBackgroundColor:)]) { statusBar.backgroundColor = color; } }

Rápido

func setStatusBarBackgroundColor(color: UIColor) { guard let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView else { return } statusBar.backgroundColor = color }

Swift 3

func setStatusBarBackgroundColor(color: UIColor) { guard let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView else { return } statusBar.backgroundColor = color }

Llamar a esta application:didFinishLaunchingWithOptions formulario application:didFinishLaunchingWithOptions funcionó para mí.

NB: tenemos una aplicación en la tienda de aplicaciones con esta lógica. Así que supongo que está bien con la política de la tienda de aplicaciones.

Editar:

Úselo bajo su propio riesgo. Forma el comentarista @Sebyddd

Tuve una aplicación rechazada como causa de esto, mientras que otra fue aceptada sin problemas. Lo consideran uso privado de API, por lo que está sujeto a la suerte durante el proceso de revisión :) - Sebyddd