title: Apply rich text format on selected text of UITextView in iOS
body: <p>I am creating an app in which i have to implement functionality like this:</p>
  
  <p>1) Write into textview</p>
  
  <p>2) Select text from textview</p>
  
  <p>3) Allow user to apply bold,italic and underline functionality on selected text.</p>
  
  <p>I have started implementing it using NSMutableAttributedString. It's working for bold and italic but replaces the textview text with only selected text. </p>
  
  <pre><code>-(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;
  
  }
  </code></pre>
  
  <p>Can anybody please help me out to implement this functionality?</p>
  
  <p>Thanks in advance.</p>