I am creating an application in which I have to implement such functions:
1) Write to text box
2) Select the text from the text box
3) Allow the user to apply bold, italic and underlined functions for the selected text.
I started implementing it using NSMutableAttributedString. It works in bold and italics, but replaces text with only selected text.
-(void) textViewDidChangeSelection:(UITextView *)textView { rangeTxt = textView.selectedRange; selectedTxt = [textView textInRange:textView.selectedTextRange]; NSLog(@"selectedText: %@", selectedTxt); } -(IBAction)btnBold:(id)sender { UIFont *boldFont = [UIFont boldSystemFontOfSize:self.txtNote.font.pointSize]; NSDictionary *boldAttr = [NSDictionary dictionaryWithObject:boldFont forKey:NSFontAttributeName]; NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc]initWithString:selectedTxt attributes:boldAttr]; txtNote.attributedText = attributedText; }
Can anyone help me implement this functionality?
Thanks in advance.
source share