2013-04-22 2 views
-1

Вот код: -NSTextAlignmentJustified бросает ошибку

lblValue является экземпляром UILabel.

[lblValue setText:@"Some Big String"]; 
[lblValue setTextAlignment: NSTextAlignmentJustified]; 

Ошибка: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textAlignment does not accept NSTextAlignmentJustified'

+0

NSTextFieldAlignement работает только с iOS6. Если вы ориентируетесь на iOS5 или iOS4.3, это не сработает. – Larme

ответ

2

Если вы используете iOS6 то UITextAlignment осуждается. Вы можете NSAttributedString, или вы можете использовать некоторые сторонние атрибуты Labels с точным выравниванием для этой цели.

UIKit

NSString drawing additions and UILabel do not support NSTextAlignmentJustified orNSTextAlignmentNatural text alignments. Instead, use NSAttributedString drawing additions, which do support text alignments.

From UILabel Docs

If you are using styled text in iOS 6 or later, assigning a new value to this property causes the text alignment to be applied to the entirety of the string in the attributedText property. If you want to apply the alignment to only a portion of the text, create a new attributed string with the desired style information and associate it with the label. If you are not using styled text, this property applies to the entire text string in the text property.

+0

Я использую NSTestAlignment, а не UITextAlignment –

+0

Вы должны создать привязанную строку для установки выравнивания для этой цели. – nsgulliver

+0

Не могли бы вы показать мне пример кода для этого? –

Смежные вопросы