From 013dc25561d022d26289f8f18715b9f9976e334f Mon Sep 17 00:00:00 2001 From: Jonathan Crooke Date: Thu, 18 Jun 2015 16:34:27 +0200 Subject: [PATCH] Add attributed accessors --- class/HPGrowingTextView.h | 1 + class/HPGrowingTextView.m | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/class/HPGrowingTextView.h b/class/HPGrowingTextView.h index 8b343c5..01472c6 100644 --- a/class/HPGrowingTextView.h +++ b/class/HPGrowingTextView.h @@ -95,6 +95,7 @@ //uitextview properties @property(unsafe_unretained) NSObject *delegate; @property(nonatomic,strong) NSString *text; +@property(nonatomic,strong) NSAttributedString *attributedText; @property(nonatomic,strong) UIFont *font; @property(nonatomic,strong) UIColor *textColor; @property(nonatomic) NSTextAlignment textAlignment; // default is NSTextAlignmentLeft diff --git a/class/HPGrowingTextView.m b/class/HPGrowingTextView.m index 9871c6f..dfe8d2a 100644 --- a/class/HPGrowingTextView.m +++ b/class/HPGrowingTextView.m @@ -425,16 +425,30 @@ -(BOOL)isFirstResponder -(void)setText:(NSString *)newText { - internalTextView.text = newText; - - // include this line to analyze the height of the textview. - // fix from Ankit Thakur - [self performSelector:@selector(textViewDidChange:) withObject:internalTextView]; + internalTextView.text = newText; + + // include this line to analyze the height of the textview. + // fix from Ankit Thakur + [self performSelector:@selector(textViewDidChange:) withObject:internalTextView]; } -(NSString*) text { - return internalTextView.text; + return internalTextView.text; +} + +-(void)setAttributedText:(NSAttributedString *)newText +{ + internalTextView.attributedText = newText; + + // include this line to analyze the height of the textview. + // fix from Ankit Thakur + [self performSelector:@selector(textViewDidChange:) withObject:internalTextView]; +} + +-(NSAttributedString*) attributedText +{ + return internalTextView.attributedText ?: [[NSAttributedString alloc] initWithString:self.text]; } ///////////////////////////////////////////////////////////////////////////////////////////////////