Created
April 18, 2014 06:44
-
-
Save kylestew/11028041 to your computer and use it in GitHub Desktop.
KSCenteredTextView - Auto Vertical Centering UITextView
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
#import <UIKit/UIKit.h> | |
@interface KSCenteredTextView : UITextView | |
@end | |
#import "KSCenteredTextView.h" | |
@implementation KSCenteredTextView | |
- (void)layoutSubviews { | |
CGRect saveFrame = self.frame; | |
[self sizeToFit]; | |
float height = self.frame.size.height; | |
self.frame = saveFrame; | |
float inset = (self.frame.size.height - height) / 2.0f; | |
self.contentOffset = CGPointMake(0, -inset); | |
} | |
- (void)setText:(NSString *)text { | |
[super setText:text]; | |
[self setNeedsLayout]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment