Skip to content

Commit

Permalink
[fixed] Scrolling not working on preloaded text
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspinckaers committed Aug 5, 2011
1 parent bafdc19 commit ef1d120
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions class/HPGrowingTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ @implementation HPGrowingTextView
@synthesize internalTextView;
@synthesize delegate;

@synthesize text;
@synthesize font;
@synthesize textColor;
@synthesize textAlignment;
Expand Down Expand Up @@ -76,8 +75,15 @@ - (id)initWithFrame:(CGRect)frame {
-(void)sizeToFit
{
CGRect r = self.frame;
r.size.height = minHeight;
self.frame = r;

// check if the text is available in text view or not, if it is available, no need to set it to minimum lenth, it could vary as per the text length
// fix from Ankit Thakur
if ([self.text length] > 0) {
return;
} else {
r.size.height = minHeight;
self.frame = r;
}
}

-(void)setFrame:(CGRect)aframe
Expand Down Expand Up @@ -251,14 +257,18 @@ - (void)dealloc {
#pragma mark UITextView properties
///////////////////////////////////////////////////////////////////////////////////////////////////

-(void)setText:(NSString *)atext
-(void)setText:(NSString *)newText
{
internalTextView.text= atext;
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

-(NSString*) text
{
return internalTextView.text;
return internalTextView.text;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion example/Classes/GrowingTextViewExampleViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (void)loadView {
textView.returnKeyType = UIReturnKeyGo; //just as an example
textView.font = [UIFont boldSystemFontOfSize:15.0f];
textView.delegate = self;
//textView.text = @"test\n\ntest";
textView.text = @"test\n\ntest";
//textView.animateHeightChange = NO; //turns off animation

[self.view addSubview:textView];
Expand Down

0 comments on commit ef1d120

Please sign in to comment.