Reputation: 2481
In the UITextView
text,
before highlight the text, its shown the text size as 16. (in the first image)
after the using the NSAttributedString
to highlight. highlighted text only show that same size(16) remaining strings show lesser than that the original size (second .
this problem only in the iPod
and iPhone
deceive . iPad
is shown correct format.
code to highlight the UITextView
Text
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:[UIFont fontWithName:@"Arial" size:currentTextSize] forKey:NSFontAttributeName];
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:txtview4disp.text];
int startind=[[dict objectForKey:@"BeginIndexPos"]integerValue];
int endind=[[dict objectForKey:@"EndIndexPos"]integerValue];
NSRange rang;
if (startind>=STARTINDEX&&startind<=ENDINDEX) {
if (endind>ENDINDEX) {
int endind2=endind-ENDINDEX;
rang=NSMakeRange(startind-STARTINDEX, (endind-startind)-endind2);
}
else
rang=NSMakeRange(startind-STARTINDEX, endind-startind);
[attrString addAttributes:attrsDictionary range:rang];
[attrString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:rang];
txtview4disp.attributedText=attrString;
Upvotes: 0
Views: 388
Reputation: 26907
It looks like you skipped the original attributes of your UITextView
.
Try replacing this line:
NSMutableAttributedString *attrString =
[[NSMutableAttributedString alloc] initWithString:txtview4disp.text];
with following:
NSMutableAttributedString *attrString =
[[NSMutableAttributedString alloc] initWithAttributedString:txtview4disp.attributedText];
Upvotes: 1