次のような機能を実装する必要があるアプリを作成しています。
1) テキストビューに書き込む
2) テキストビューからテキストを選択
3) ユーザーが選択したテキストに太字、斜体、下線の機能を適用できるようにします。
NSMutableAttributedString を使用して実装を開始しました。太字と斜体で機能しますが、テキストビューのテキストを選択したテキストのみに置き換えます。
-(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;
}
この機能を実装するのを手伝ってくれる人はいますか?
前もって感謝します。