2016-09-30 57 views
0

在屬性檢查器上,我在UITextView選項卡中將.text屬性設置爲「屬性」,然後將「行」值更改爲1.5。當.text值更改時,UITextView行距回到默認值

當一個新值分配給UITextView中的.text字段時,行間距被設置回來。

enter image description here

左邊一個是在main.storyboard所示的視圖控制器和右側是分配在UITextViewString值,在模擬器中運行之後的結果。

有沒有像約束或東西讓我來修改.text後行間距值?我認爲它應該由代碼管理..

let style = NSMutableParagraphStyle() 
style.lineSpacing = 40 
let attributes = [NSParagraphStyleAttributeName : style] 
aboutNeyong.attributedText = 
NSAttributedString(string: aboutNeyong.text!, attributes:attributes) 

上面的代碼是我在賦值語句後添加的。

+0

展示你是如何設置的文本? –

+0

你設置myTextView.text =東西或myTextView.attributedText =東西? –

+0

@UmairAfzal它就像'UITextView.text = String()'; –

回答

1

必須設定最高和最低高度

例如:

style.maximumLineHeight = 10 style.minimumLineHeight = 10

0

嘗試設置UITextField的「屬性文本」字段而不是「文本」字段。確保你與期望間距的屬性串傳遞:

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
paragraphStyle.lineSpacing = 15; // Desired line spacing here 
NSDictionary *attrsDictionary = @{ NSParagraphStyleAttributeName: paragraphStyle }; 

textView.attributedText = [[NSAttributedString alloc] initWithString:@"Your new string here!" attributes:attrsDictionary]; 
+0

我編輯了這個問題;你能檢查爲什麼添加的語句不作任何改變?即使使用上面的代碼,它也不會改變。 –