Created
July 28, 2011 19:00
-
-
Save adeel/1112262 to your computer and use it in GitHub Desktop.
UITextField category for conveniently adding text fields inside frames with padding.
This file contains hidden or 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
// | |
// UITextField+withFrame.h | |
// | |
#import <Foundation/Foundation.h> | |
@interface UITextField (withFrame) | |
+ (UITextField *)textFieldWithFrame:(CGRect)frame | |
font:(UIFont *)font; | |
+ (UITextField *)textFieldWithFrame:(CGRect)frame | |
font:(UIFont *)font | |
padding:(CGFloat)padding; | |
@end |
This file contains hidden or 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
// | |
// UITextField+withFrame.m | |
// | |
#import "UITextField+withFrame.h" | |
@implementation UITextField (withFrame) | |
// Create a text field inside the frame with 8pt of horizontal padding. | |
+ (UITextField *)textFieldWithFrame:(CGRect)frame | |
font:(UIFont *)font { | |
return [UITextField textFieldWithFrame:frame font:font padding:8.0f]; | |
} | |
+ (UITextField *)textFieldWithFrame:(CGRect)frame | |
font:(UIFont *)font | |
padding:(CGFloat)padding { | |
UITextField *field = [[[UITextField alloc] initWithFrame:CGRectZero] autorelease]; | |
field.font = font; | |
[field sizeToFit]; | |
field.frame = CGRectMake( | |
frame.origin.x + 5.0f, frame.origin.y + (frame.size.height - field.frame.size.height) / 2.0f, | |
frame.size.width - 10.0f, field.frame.size.height); | |
return field; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment