In my App i have a UItextView and its input view has accessory view with couple of buttons on it.
I am trying to change the text already being typed to underline text. Its working fine but its loosing the font and the font size after conversion.
Here's what i am doing:
NSRange selectedRange = [self.commentsTextView selectedRange];
NSDictionary *currentAttributesDict = [self.commentsTextView.textStorage attributesAtIndex:selectedRange.location
effectiveRange:nil];
NSDictionary *dict;
if ([currentAttributesDict objectForKey:NSUnderlineStyleAttributeName] == nil ||
[[currentAttributesDict objectForKey:NSUnderlineStyleAttributeName] intValue] == 0) {
dict = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInt:1]};
}
else{
dict = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInt:0]};
}
[self.commentsTextView.textStorage beginEditing];
[self.commentsTextView.textStorage setAttributes:dict range:selectedRange];
[self.commentsTextView.textStorage endEditing];