Cambiar el color del tinte global - iOS7/iOS8


¿Cómo podemos cambiar el color de tinte global en iOS7/iOS8 por código? Quiero cambiar varios objetos que usan esta propiedad, pero no cambiar cada uno, por eso quiero usar la propiedad global tint.

Author: elGeekalpha, 2013-09-23

5 answers

Simplemente cambie los UIWindow 's tintColor en su delegado de solicitud, se pasa automáticamente como predeterminado a todos sus UIView descendientes.

[self.window setTintColor:[UIColor greenColor]];
 105
Author: Vinzzz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-06-21 13:05:19

[[UIView appearance] setTintColor:[UIColor greenColor]];

 65
Author: carmen_munich,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-10-02 15:24:14

Hay dos maneras de cambiar su color de tinte global. Como muchos de los mencionados anteriormente, puedes cambiar self.window.tintColor en -application:didFinishLaunchingWithOptions:.

Una forma más elegante, en mi opinión, es establecer Tinte global en Inspector de archivos en su guion gráfico mientras no se selecciona nada. De esta manera su -application:didFinishLaunchingWithOptions: es más limpio.

Tinte Global en el Inspector de Archivos

 32
Author: totocaster,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-08 06:43:40

Puede especificar un color de tinte para toda la aplicación configurando la propiedad de tinte de la ventana. Para hacer esto, puede usar un código similar al siguiente:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.tintColor = [UIColor purpleColor];
    return YES;
}
 12
Author: Gerardo Blanco García,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-02 16:11:29

Actualizado para Swift 2.2

Puedes hacer esto desde cualquier lugar como este:

// Get app delegate
let sharedApp = UIApplication.sharedApplication()

// Set tint color
sharedApp.delegate?.window??.tintColor = UIColor.green()

O si estás tratando de hacer esto desde AppDelegate,

//self.window?.tintColor = UIColor.green()
 2
Author: Tulio Troncoso,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-17 16:35:28