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

时间:2014-12-04 04:33:29

标签: ios uitextview nsattributedstring

在我的UITextView中,我希望某些NSRanges左右缩进,并以特定颜色突出显示。我通过修改NSMutableAttributedStrings并设置textView.attributedText来实现这一目标。要获得左/右缩进,我正在使用NSMutableParagraphStyle - 但是,这会删除突出显示(NSBackgroundColor)。如何突出显示从头开始,即使使用headIndent

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};

1 个答案:

答案 0 :(得分:0)

使用以下代码在UITextView中提供填充

self.textView.textContainer.lineFragmentPadding = 0;