Last active
August 29, 2015 14:07
-
-
Save johanforssell/94e089707d5823ab1fdf to your computer and use it in GitHub Desktop.
A useful UITextView subclass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://github.com/Nikita2k/resizableTextView | |
#import <UIKit/UIKit.h> | |
// --------------------------------------- | |
@interface ResizableTextView : UITextView | |
@end | |
// --------------------------------------- | |
@implementation ResizableTextView | |
- (void) updateConstraints { | |
// calculate contentSize manually | |
// ios7 doesn't calculate it before viewDidAppear and we'll get here before | |
CGSize contentSize = [self sizeThatFits:CGSizeMake(self.frame.size.width, FLT_MAX)]; | |
// set the height constraint to change textView height | |
[self.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop) { | |
if (constraint.firstAttribute == NSLayoutAttributeHeight) { | |
constraint.constant = contentSize.height; | |
*stop = YES; | |
} | |
}]; | |
[super updateConstraints]; | |
} | |
- (void)setContentOffset:(CGPoint)contentOffset | |
{ | |
// In iOS 8 we seem to be inheriting the content offset from the parent. | |
// I'm not interested! | |
// This is the "do nothing" override. | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment