ios - NSTextView with long NSMutableAttributedText low scrolling and loading speed -
i have uitextview of times should show long attributedtexts. utilize below code creating attributed text:
//add each line of doa element of array future usage nsarray *paragraphs = [self.text componentsseparatedbystring:@"\r\n"]; mixedcontent= [[nsmutableattributedstring alloc]init]; arabiccontent= [[nsmutableattributedstring alloc]init]; translatedcontent= [[nsmutableattributedstring alloc]init]; nsstring * temp=@""; (int i=0; i< paragraphs.count; i++) { if([paragraphs[i] hasprefix:@"$2."]){ temp= [paragraphs[i] stringbyreplacingoccurrencesofstring:@"$2." withstring:@"" options:1 range:nsmakerange(0, 3)]; nsmutableattributedstring* tempmutable= [[nsmutableattributedstring alloc] initwithstring:temp attributes:doadescriptionattributes]; //go next line [tempmutable appendattributedstring:[[nsmutableattributedstring alloc] initwithstring:@"\n\n"]]; [arabiccontent appendattributedstring: tempmutable]; [translatedcontent appendattributedstring:tempmutable]; [mixedcontent appendattributedstring:tempmutable]; }else if ([paragraphs[i] rangeofstring:@"$3."].location != nsnotfound){ temp= [paragraphs[i] stringbyreplacingoccurrencesofstring:@"$3." withstring:@"" options:1 range:nsmakerange(0, 3)]; nsmutableattributedstring* tempmutable= [[nsmutableattributedstring alloc] initwithstring:temp attributes:arabicdoaattributes]; [mixedcontent appendattributedstring:tempmutable]; [mixedcontent appendattributedstring:[[nsmutableattributedstring alloc] initwithstring:@"\n"]]; [arabiccontent appendattributedstring:tempmutable]; [arabiccontent appendattributedstring: [[nsmutableattributedstring alloc] initwithstring:@" "]]; }else if ([paragraphs[i] rangeofstring:@"$4."].location != nsnotfound){ temp= [paragraphs[i] stringbyreplacingoccurrencesofstring:@"$4." withstring:@"" options:1 range:nsmakerange(0, 3)]; nsmutableattributedstring* tempmutable= [[nsmutableattributedstring alloc] initwithstring:temp attributes:arabicdoaattributes]; [mixedcontent appendattributedstring:tempmutable]; [mixedcontent appendattributedstring:[[nsmutableattributedstring alloc] initwithstring:@"\n"]]; [translatedcontent appendattributedstring:tempmutable]; [translatedcontent appendattributedstring: [[nsmutableattributedstring alloc] initwithstring:@" "]]; } temp=nil; } } my text contain 3 kind of text. description. standard arabic text , translation. each of part showing specific color.
and utilize code setting text:
self.mytextview.attributedtext= myattributedtext; the problem when set or alter text of textview takes 2 seconds app set or update text. waiting time not users.
also when scroll textview not @ all. scroll paragraphs , stop , scroll, stop , scroll,....
actually slow on scrolling.
is there improve ways setting text have improve performance?
update
i ma thinking whethere possible load text scrolling. thing lazy loader list uitextview. possible?
update
when add together text without attributes. (i mean lines same color) scroll works fine.
update
it amount of texts. when cut down amount of texts. illustration instead of setting 10000 character set 500 character , pretty fast. how can prepare it?
ios uitextview nsattributedstring nsmutableattributedstring
No comments:
Post a Comment