Sunday, June 2, 2013

UITextField UITextBorderStyleRoundedRect example in Objective C (iOS).


UITextField UITextBorderStyleRoundedRect

UITextFieldBorderStyle
The type of border drawn around the text field.

typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;

Constants
UITextBorderStyleNone
The text field does not display a border.
UITextBorderStyleLine
Displays a thin rectangle around the text field.
UITextBorderStyleBezel
Displays a bezel-style border for the text field. This style is typically used for standard data-entry fields.
UITextBorderStyleRoundedRect
Displays a rounded-style border for the text field.

UITextField UITextBorderStyleRoundedRect example.
int labelWidth = 100;
int labelHeight = 10;

_maxPriceField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, labelWidth, labelHeight)];
_maxPriceField.borderStyle     = UITextBorderStyleRoundedRect;
_maxPriceField.clearButtonMode = UITextFieldViewModeWhileEditing;

//_maxPriceField.font            = fieldFont;
//_maxPriceField.delegate        = self;
[self.view addSubview:_maxPriceField];

UITextField *secondField = [[UITextField alloc] initWithFrame:CGRectMake(10, 40, labelWidth, labelHeight + 10)];
secondField.borderStyle     = UITextBorderStyleRoundedRect;
[self.view addSubview:secondField];
[secondField release];

Example of [UITextField UITextBorderStyleRoundedRect].
    UITextField *mobileNumberField = [[UITextField alloc] initWithFrame:CGRectMake(10, 195, 300, 41)];
    mobileNumberField.delegate = self;
    mobileNumberField.layer.borderWidth = 1.0f;
    mobileNumberField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    mobileNumberField.
    mobileNumberField.borderStyle = UITextBorderStyleRoundedRect;
    [mobileNumberField.layer setCornerRadius:14.0f];
    mobileNumberField.placeholder = @"Mobile Number";
    [self.paymentsHomeView addSubview:mobileNumberField];

UITextField UITextBorderStyleRoundedRect example.
-(IBAction)addTextField:(id)sender{
    float x=previousTextField.frame.origin.x;
    float y=previousTextField.frame.origin.y+50;//get y from previous textField and add 10 or so in it.
    float w=previousTextField.frame.size.width;
    float h=previousTextField.frame.size.height;
    CGRect frame=CGRectMake(x,y,w,h);
    UITextField *textField=[[UITextField alloc] initWithFrame:frame];
    textField.placeholder = @"Enter User Name or Email";

    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.font = [UIFont systemFontOfSize:15];
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.keyboardType = UIKeyboardTypeDefault;
    textField.returnKeyType = UIReturnKeyDone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;

    [self.view addSubview:textField];
    previousTextField=textField;
}

End of UITextField UITextBorderStyleRoundedRect example article.