iOS-UIBarButtonItem Identifier-opción para crear" ajustes " botón de rueda dentada
Quiero crear un UIBarButtonItem para representar la configuración de la aplicación (rueda dentada). Actualmente solo puedo encontrar una opción para crear UIBarButtonItem (Constructor de interfaz > Inspector de atributos > identificador) como "Add" ( + ), "Edit", "Done", "Cancel" etc
No puedo encontrar una opción para crear un icono de configuración (rueda dentada). ¿Hay alguna forma de hacer esto en interface builder o a través del código?
¿O tengo que crear una imagen y luego la imagen ?
4 answers
Unicode tiene varios ejemplos notables que puedes simplemente copiar y pegar en una declaración de cadena en Xcode, o usar el Escape de cadena Unicode estándar (\uxxxx) y iOS es bastante fluido cuando se trata de Unicode (sé que algunos de los caracteres son bastante feos, pero eso es Unicode para ti):
Carácter Unicode ' ENGRANAJE SIN BUJE '(U+26ED): http://www.fileformat.info/info/unicode/char/26ed/index.htm
Carácter Unicode 'ENGRANAJE' (U+2699): http://www.fileformat.info/info/unicode/char/2699/index.htm
O prepare una imagen y establezca la propiedad CustomView de UIBarButtonItem en consecuencia.
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
2012-03-18 03:14:13
Componiendo CodaFi y user1046037 respuestas:
Creando UIBarButtonItem con carácter unicode como título.
Tienes que inicializar UIBarButtonItem
con title (initWithTitle:
) no system item (initWithBarButtonSystemItem:
).
Puede establecer un título personalizado con una cadena (como un carácter unicode).
Puede cambiar el tamaño del título.
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"\u2699" style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];
UIFont *customFont = [UIFont fontWithName:@"Helvetica" size:24.0];
NSDictionary *fontDictionary = @{NSFontAttributeName : customFont};
[settingsButton setTitleTextAttributes:fontDictionary forState:UIControlStateNormal];
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-03-24 17:35:36
Para obtener el icono de la rueda dentada usando Swift, haga lo siguiente en viewDidLoad()
, suponiendo que haya conectado el botón de su vista a su controlador. (Ex: @IBOutlet var settingsButton: UIBarButtonItem!
)
self.settingsButton.title = NSString(string: "\u{2699}") as String
if let font = UIFont(name: "Helvetica", size: 18.0) {
self.settingsButton.setTitleTextAttributes([NSFontAttributeName: font], forState: UIControlState.Normal)
}
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-04-26 07:37:15
Esto funciona para mí en Swift 3 y iOS 10...
let settingsButton = UIBarButtonItem(title: NSString(string: "\u{2699}\u{0000FE0E}") as String, style: .plain, target: self, action: #selector(settings))
let font = UIFont.systemFont(ofSize: 28) // adjust the size as required
let attributes = [NSFontAttributeName : font]
settingsButton.setTitleTextAttributes(attributes, for: .normal)
Ver el comentario de @hazernut en la respuesta aceptada. Sin agregar \u{0000FE0E}
a la cadena, se muestra como un emoji y es inmune a cualquier configuración de apariencia. Agregar esa cadena soluciona eso.
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
2017-05-16 12:04:26