Wednesday, July 25, 2012

How to add left padding to the UITextField, when add background Image


#import "QuartzCore/QuartzCore.h"    // First import this Framework
......



UITextField *_emailText = [[UITextField alloc]initWithFrame:CGRectMake(40, 8, 250, 34)];
//    _emailText.borderStyle = UITe;  // Please set borderStyle to default value, otherwise it is not working.
    _emailText.delegate = self;
    _emailText.placeholder = @"Email";
    [_emailText setFont:[UIFont boldSystemFontOfSize:12]];
    _emailText.tag = 1;
    _emailText.returnKeyType = UIReturnKeyNext;
    _emailText.textAlignment = UITextAlignmentLeft;
    _emailText.keyboardType = UIKeyboardTypeEmailAddress;
    _emailText.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    _emailText.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    _emailText.leftViewMode = UITextFieldViewModeAlways;
    _emailText.background = [[UIImage imageNamed:@"textBox.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];
    [self.view addSubview:_emailText];

No comments:

Post a Comment

Add your comment