2013-04-22 181 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 2013-04-22 10:23:08

回答

2

如果您正在使用iOS6的那麼UITextAlignment已被棄用。您可以NSAttributedString或者您可以使用某些第三方歸因的標籤進行精細對齊以達到此目的。

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 – 2013-04-22 10:23:19

+0

您應該爲此目的創建一個歸因字符串來設置對齊。 – nsgulliver 2013-04-22 10:27:46

+0

你能告訴我一些示例代碼來實現嗎? – 2013-04-22 10:31:08