theme temas tema tareas personalizar personalizado google fondo como color chrome cambiar buscador barra iphone ios objective-c ios7

iphone - temas - Cómo cambiar el color del texto del elemento de la barra de pestañas



personalizar google fondo (8)

¿Cómo puedo cambiar el color del texto "Más ..." en la barra de tabulación para que coincida con el color de su icono? (Ahora el rendimiento se selecciona en la barra de pestañas)

Traté de establecer TitleTextAttributes.

[moreItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName, [UIColor yellowColor],NSForegroundColorAttributeName , nil]

Pero el color del texto siempre se establece en amarillo. incluso cuando el artículo está seleccionado. Me gusta esto

Estoy tratando de establecer en blanco cuando se selecciona y cuando no seleccionado debe coincidir con el color del icono. Gracias ... Cualquier sugerencia será realmente útil.


Esta es la versión rápida:

for item in self.mainTabBar.items! { let unselectedItem: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()] let selectedItem: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()] item.setTitleTextAttributes(unselectedItem as? [String : AnyObject], forState: .Normal) item.setTitleTextAttributes(selectedItem as? [String : AnyObject], forState: .Selected) }

O simplemente puede cambiar en Appdelegate: -

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blueColor()], forState: .Selected) UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.blackColor()], forState: .Normal) // Override point for customization after application launch. return true }


Encontré la respuesta para mi propia pregunta.

Podemos establecer perforamceItem setTitleTextAttributes: para dos estados diferentes.

  • forState:UIControlStateNormal
  • forState:UIControlStateHighlighted

Agregué el siguiente código

[performanceItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName, [UIColor yellowColor], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal]; [performanceItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaLTStd-Roman" size:10.0f], NSFontAttributeName, [UIColor whiteColor], NSForegroundColorAttributeName,nil] forState:UIControlStateHighlighted];

Necesito reemplazar el color amarillo con el color de mis ICONOS. Así es como están mirando ahora.

Cuando se selecciona Más

Cuando se selecciona la ejecución


El código de la respuesta aceptada no funciona para mí.

Aquí hay un código que funciona:

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor yellowColor] } forState:UIControlStateNormal]; [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] } forState:UIControlStateSelected];


Para una solución rápida, permita que la inferencia tipo sea su amigo:

override func viewWillAppear(animated: Bool) { for item in self.tabBar.items! { let unselectedItem = [NSForegroundColorAttributeName: UIColor.blackColor()] let selectedItem = [NSForegroundColorAttributeName: UIColor.whiteColor()] item.setTitleTextAttributes(unselectedItem, forState: .Normal) item.setTitleTextAttributes(selectedItem, forState: .Selected) } }


Esto es fácil, simplemente subclase UITabBarItem y asigne que sea la clase de su elemento de barra de pestañas en el guión gráfico o el código. El siguiente funciona perfectamente para mí.

import UIKit class PPTabBarItem: UITabBarItem { required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) commonInit() } override init() { super.init() commonInit() } func commonInit() { self.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(13), NSForegroundColorAttributeName:UIColor.blackColor()], forState: UIControlState.Normal) self.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(13), NSForegroundColorAttributeName:UIColor.yellowColor()], forState: UIControlState.Selected) } }

La solución de skywinder es buena pero desencadena un alcance global.


La versión Swift de @skywinder responde:

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.whiteColor()], forState: .Normal) UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.whiteColor()], forState: .Selected)


Código de forma gratuita para hacer esto:

Si solo está usando iOS 10, puede cambiar el Tono de la imagen en su Barra de pestañas

Si también admite iOS 9 y versiones anteriores, también debe agregar tintColor a los atributos de tiempo de ejecución de su usuario en cada elemento de la barra de pestañas

Si también desea cambiar el color de su icono, asegúrese de que la imagen de color correcta se encuentre en su carpeta de assest y cambie Render como en la Imagen original.


Esto funciona correctamente ...

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected]; [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];