UILabel Alinear texto al centro
¿Cómo alineo texto en UILabel
?
9 answers
Desde iOS 6 y posteriores UITextAlignment
está obsoleto. use NSTextAlignment
myLabel.textAlignment = NSTextAlignmentCenter;
Versión Swift de iOS 6 y posteriores
myLabel.textAlignment = .center
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
2018-04-30 11:58:35
Aquí hay un código de ejemplo que muestra cómo alinear texto usando UILabel:
label = [[UILabel alloc] initWithFrame:CGRectMake(60, 30, 200, 12)];
label.textAlignment = NSTextAlignmentCenter;
Puedes leer más al respecto aquí UILabel
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-07-28 19:03:44
Para centrar el texto en una etiqueta UILabel en Swift (que está dirigida para iOS 7+) puede hacer:
myUILabel.textAlignment = .Center
O
myUILabel.textAlignment = NSTextAlignment.Center
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-08-24 04:34:43
N.B.: De acuerdo con la referencia de clase UILabel , a partir de iOS 6 este enfoque ahora está obsoleto.
Simplemente use la propiedad textAlignment
para ver la alineación requerida usando uno de los valores UITextAlignment
. (UITextAlignmentLeft
, UITextAlignmentCenter
o UITextAlignmentRight
.)
E. g.: [myUILabel setTextAlignment:UITextAlignmentCenter];
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-01 09:31:48
Use yourLabel.textAlignment = NSTextAlignmentCenter;
para iOS >= 6.0 y yourLabel.textAlignment = UITextAlignmentCenter;
para iOS
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-02-12 23:25:33
Para Swift 3 es:
label.textAlignment = .center
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-12-19 09:27:38
IO6.1
[lblTitle setTextAlignment:NSTextAlignmentCenter];
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-04-19 07:25:01
Label.textAlignment = NSTextAlignmentCenter;
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-07-18 10:26:10
En xamarin ios supongamos que el nombre de su etiqueta es title y luego haga lo siguiente
title.TextAlignment = UITextAlignment.Center;
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-12-16 07:11:25