iOS AttributedText删除/ n换行符

时间:2014-11-16 02:44:18

标签: ios uiwebview nsattributedstring

我试图在收集的各种报价之间插入一些行间距。我使用的代码是:

if (!self.theArray) {

        self.theArray = [[NSMutableArray alloc] init];

    }


    NSString *doIt = [NSString stringWithFormat:@"%@ - %@ %@:%@", self.textstring, self.bookstring, self.chapterstring, self.versestring];
    [self.theArray addObject:doIt];
    NSString *theEnd = [self.theArray componentsJoinedByString:@"\n"];

    NSString *loadHTML = [@"<head> <style type='text/css'>a > img {pointer-events: none;cursor: default;}</style></head><b><div align=\"left\"><font size=5>"  stringByAppendingString:theEnd];
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[loadHTML dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
    textView.attributedText = attributedString;
    [self performSelector:@selector(startTheProcess) withObject:self afterDelay:1.0];
    NSLog(@"ARRAY:  %@", self.theArray);
    NSLog(@"String:  %@", theEnd);

在数组和NSAttributedString的日志中,它显示换行符,但是当UIWebView显示换行符时,会删除换行符。

1 个答案:

答案 0 :(得分:1)

替换

NSString *theEnd = [self.theArray componentsJoinedByString:@"\n"];

有了这个,

NSString *theEnd = [self.theArray componentsJoinedByString:@"<br>"];