Created
November 9, 2011 23:24
-
-
Save Shilo/1353522 to your computer and use it in GitHub Desktop.
A simple category for Sparrow that allows one to auto size an SPTextField.
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
// | |
// SPTextField+AutoSize.h | |
// Sparrow | |
// | |
// Created by Shilo White on 9/17/11. | |
// Copyright 2011 Shilocity Productions. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
@interface SPTextField (AutoSize) | |
- (SPRectangle *)textBounds; | |
- (void)autoSizeBounds; | |
- (void)autoSizeWidth; | |
- (void)autoSizeHeight; | |
@end |
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
// | |
// SPTextField+AutoSize.m | |
// Sparrow | |
// | |
// Created by Shilo White on 9/17/11. | |
// Copyright 2011 Shilocity Productions. All rights reserved. | |
// | |
#import "SPTextField+AutoSize.h" | |
@implementation SPTextField (AutoSize) | |
- (SPRectangle *)textBounds { | |
CGSize textSize = [self.text sizeWithFont:[UIFont fontWithName:self.fontName size:self.fontSize] constrainedToSize:CGSizeMake(self.width, self.height) lineBreakMode:UILineBreakModeTailTruncation]; | |
return [SPRectangle rectangleWithX:0 y:0 width:textSize.width height:textSize.height]; | |
} | |
- (void)autoSizeBounds { | |
SPRectangle *textBounds = [self textBounds]; | |
self.width = textBounds.width; | |
self.height = textBounds.height; | |
} | |
- (void)autoSizeWidth { | |
SPRectangle *textBounds = [self textBounds]; | |
self.width = textBounds.width; | |
} | |
- (void)autoSizeHeight { | |
SPRectangle *textBounds = [self textBounds]; | |
self.height = textBounds.height; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment