Skip to content

Commit

Permalink
[fix] Fully respects contentinset left/right
Browse files Browse the repository at this point in the history
  • Loading branch information
hanspinckaers committed Aug 7, 2011
1 parent 7b1fb92 commit e986035
Showing 2 changed files with 20 additions and 8 deletions.
16 changes: 12 additions & 4 deletions class/HPTextViewInternal.m
Original file line number Diff line number Diff line change
@@ -34,13 +34,21 @@ -(void)setContentOffset:(CGPoint)s
{
if(self.tracking || self.decelerating){
//initiated by user...
self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

UIEdgeInsets insets = self.contentInset;
insets.bottom = 0;
insets.top = 0;
self.contentInset = insets;

} else {

float bottomOffset = (self.contentSize.height - self.frame.size.height + self.contentInset.bottom);
if(s.y < bottomOffset && self.scrollEnabled){
self.contentInset = UIEdgeInsetsMake(0, 0, 8, 0); //maybe use scrollRangeToVisible?
}
if(s.y < bottomOffset && self.scrollEnabled){
UIEdgeInsets insets = self.contentInset;
insets.bottom = 8;
insets.top = 0;
self.contentInset = insets;
}

}

12 changes: 8 additions & 4 deletions example/Classes/GrowingTextViewExampleViewController.m
Original file line number Diff line number Diff line change
@@ -65,10 +65,14 @@ - (void)loadView {
textView.font = [UIFont systemFontOfSize:15.0f];
textView.delegate = self;

//textView.text = @"test\n\ntest";
//textView.animateHeightChange = NO; //turns off animation
//textView.internalTextView.contentInset = UIEdgeInsetsMake(0, 10, 0, 0);

// textView.text = @"test\n\ntest";
// textView.animateHeightChange = NO; //turns off animation

textView.internalTextView.contentInset = UIEdgeInsetsMake(0, 10, 0, 0);
CGSize s = textView.internalTextView.contentSize;
s.width -= 5; // compensate for contentInset, otherwise you get vertical scrolling
textView.internalTextView.contentSize = s;

[self.view addSubview:containerView];

[textView sizeToFit];

0 comments on commit e986035

Please sign in to comment.