2011-07-26 16 views

Respuesta

7
myLabel.textAlignment = UITextAlignmentRight; 

iOS Developer Library es un buen recurso.

+14

UITextAlignmentRight está en desuso desde iOS6. Use NSTextAlignmentRight en su lugar. – jbandi

+0

'UITextAlignmentRight' o' NSTextAlignmentRight' solo alinean a la derecha el texto, pero el texto no está justificado, vea @Hashem Aboonajmi o @Aryan answers –

1

puede ser a través del constructor de interfaz. o label.textAlignment = UITextAlignmentRight;

3

Los métodos anteriores han quedado en desuso. La nueva llamada al método es:

label.textAlignment = NSTextAlignmentRight; 
3

Se debe ajustar la alineación del texto a la dirección de escritura justificada y conjunto base una cadena con atributos a RightToLeft:

var label: UILabel = ... 
var text: NSMutableAttributedString = ... 
var paragraphStyle: NSMutableParagraphStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy() as! NSMutableParagraphStyle 
paragraphStyle.alignment = NSTextAlignment.Justified 
paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping 
paragraphStyle.baseWritingDirection = NSWritingDirection.RightToLeft 
text.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, text.length)) 
label.attributedText = text 
2

aquí es: tener cuidado si completa justificar las necesidades que deben aplicarse , firstLineIndent no debe ser cero.

NSMutableParagraphStyle* paragraph = [[NSMutableParagraphStyle alloc] init]; 
paragraph.alignment = NSTextAlignmentJustified; 
paragraph.baseWritingDirection = NSWritingDirectionRightToLeft; 
paragraph.firstLineHeadIndent = 1.0; 
NSDictionary* attributes = @{ 
          NSForegroundColorAttributeName: [UIColor colorWithRed:0.2 green:0.239 blue:0.451 alpha:1],NSParagraphStyleAttributeName: paragraph}; 
NSString* txt = @"your long text"; 
NSAttributedString* aString = [[NSAttributedString alloc] initWithString: txt attributes: attributes]; 
Cuestiones relacionadas