2014-12-04 46 views
1

在我的UITextView中,我希望某些NSRanges左右同樣縮進,並以特定顏色突出顯示。我通過修改NSMutableAttributedStrings並設置textView.attributedText來實現此目的。爲了獲得左/右縮進,我使用NSMutableParagraphStyle - 但是,這是刪除突出顯示(NSBackgroundColor)。我怎樣才能得到它,突出顯示從一開始就開始,即使是headIndentUITextView:保持左/右段落縮進的背景顏色

headIndent removes nsbackgroundcolor

// padding 
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; 
    paragraphStyle.headIndent = 5.0; 
    paragraphStyle.firstLineHeadIndent = 5.0; 
    paragraphStyle.tailIndent = -5.0; 

    NSDictionary *referenceAttributes = @{NSForegroundColorAttributeName: [UIColor lightGrayColor], NSBackgroundColorAttributeName: [UIColor brownColor], NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue-Bold" size: 14], NSParagraphStyleAttributeName: paragraphStyle}; 

回答

0

使用下面的代碼給填充在UITextView中

self.textView.textContainer.lineFragmentPadding = 0; 
+0

嗨阿希什 - 這將無法滿足,但是我在第一行上市,因爲這將適用於填充的要求到我的TextView中的所有NSRanges,而不僅僅是我感興趣的展示 – SimplyLearning 2014-12-05 01:37:48