Skip to content

Instantly share code, notes, and snippets.

@swarut
Created October 3, 2012 17:47
Show Gist options
  • Save swarut/3828564 to your computer and use it in GitHub Desktop.
Save swarut/3828564 to your computer and use it in GitHub Desktop.
Objective-C : Custom UITextField with left padding, background and keyboard hiding on exit #objective-c #textfield #customtextfield #ui #hidekeyboard
#import "RoundedTextField.h"
@implementation RoundedTextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
[self configure];
return self;
}
- (IBAction)hideKeyboard:(id)sender{
[sender resignFirstResponder];
}
- (void) configure{
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
self.leftView = paddingView;
self.leftViewMode = UITextFieldViewModeAlways;
[self addTarget:self action:@selector(hideKeyboard:) forControlEvents:UIControlEventEditingDidEndOnExit];
[self setBackground:[UIImage imageNamed:@"iphone_textbox"]];
[self setBorderStyle:UITextBorderStyleNone];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment