UITextView:保持左/右段落缩进的背景颜色

问题描述:

在我的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}; 

使用下面的代码给填充在UITextView中

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

嗨阿希什 - 这将无法满足,但是我在第一行上市,因为这将适用于填充的要求到我的TextView中的所有NSRanges,而不仅仅是我感兴趣的展示 – SimplyLearning 2014-12-05 01:37:48