2016-12-08 27 views
0

轉換我將一些RTF文本到NSAttributedString使用該代碼時設置NSAttributedText邊距(Xamarin C#,但相同的邏輯適用於夫特/的OBJ-C)如何從RTF

NSData data = NSData.FromString(RTFString); 
NSDictionary opt = NSDictionary.FromObjectAndKey(NSObject.FromObject("NSDocumentTypeDocumentAttribute"), NSObject.FromObject(NSDocumentType.RTF)); 
NSDictionary docatt = null; 
NSError error = null; 
NSAttributedString sRTF = new NSAttributedString(data, opt, out docatt, ref error); 

此效果很好,但是在轉換RTF文本時,它似乎設置了默認的右邊距值,以便文本不會流過UILabel的整個寬度。原始RTF文本中沒有設置保證金值。

如何更改或設置生成的屬性文本的右邊距值,以使其流過標籤的整個寬度?

樣品RTF

sample.rtf

{\\rtf1\\ansi\\ansicpg1252\\uc1\\htmautsp\\deff2{\\fonttbl{\\f0\\fcharset0 Times New Roman;}{\\f2\\fcharset0 Segoe UI;}}{\\colortbl\\red0\\green0\\blue0;\\red255\\green255\\blue255;\\red255\\green165\\blue0;}\\loch\\hich\\dbch\\pard\\plain\\ltrpar\\itap0{\\lang1033\\fs26\\f2\\cf0 \\cf0\\ql{\\f2 {\\b\\fs30\\cf2\\ltrch 1. Gum/Lip Irritation: }{\\fs24\\ltrch Whitening gel that comes into contact with gum tissue or the lips can become inflammed or bleached. The inflammation or whitening effect is temporary. You may feel a stinging and/or tingling sensation on these soft tissues during the treatment.2. Tooth Sensitivity: You may experience some tooth sensitivity during the first 24 hours after your treatment. Underlying tooth/gum disease such as existing sensitivity, cracked teeth, open cavities, leaking fillings, exposed roots or other dental conditions may worsen or prolong tooth sensitivity after treatment.3. Spots or Streaks: There is a potential to develop white spots or streaks on your teeth due to calcium deposits that naturally occur in teeth. These spots are not caused by Beaming White gel. The gel just brings these calcium deposits out and makes them more visible. This effect will fade over time.4. Relapse: After your treatment, it is natural for teeth color to regress over time. This relapse can be slowed down by avoiding staining agents such as coffee, tea, tobacco, red wine, colas etc. It is very important to avoid these staining agents, especially during the first 24 hours after treatment. I understand that the results of my treatment are not permanent, that up to 3 applications may be needed for desired effect and maintanence treatment every recommended very 4-6 months.}\\li0\\ri0\\sa0\\sb0\\fi0\\ql\\par}\r\n}\r\n} 

Yellow shows extent of UITextView, with right margin

+0

*假設*這是一個多行'UILabel',你有一個樣品'。 rtf'表現出右手邊距,因爲我還沒有看到這個問題。我遇到了一些包含奇怪偏移的rtf,而不是編輯客戶端的原始文件,我用否定的'UIEdgeInsets'來調整「邊距」以使文本重新排列。 – SushiHangover

+0

@SushiHangover請參閱編輯示例RTF和行爲屏幕截圖 – Jason

+0

@Jason我不是rtf的專家,但是如果使用TextEdit打開文件,它將以非常相似的方式包裝行。也許文件本身有這樣的格式。 –

回答

0

插入極右保證金(\margrXXXX),或只是0應該也工作之一,但並不總是(?),覆蓋rtf字符串的默認邊距以允許UILabel.Frame的全部寬度用於段落迴流點。

前:

enter image description here

後:

{\rtf1\ansi\ansicpg1252\uc1\htmautsp\margr20000\deff2{\fo...‌​

enter image description here