Sunday, June 2, 2013

UITextField UITextBorderStyleBezel example in Objective C (iOS).


UITextField UITextBorderStyleBezel

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 UITextBorderStyleBezel example.
- (UITextField *)textFieldNormal
{
    if (textFieldNormal == nil)
    {
        CGRect frame = CGRectMake(kLeftMargin, 8.0, kTextFieldWidth, kTextFieldHeight);
        textFieldNormal = [[UITextField alloc] initWithFrame:frame];

        textFieldNormal.borderStyle = UITextBorderStyleBezel;
        textFieldNormal.textColor = [UIColor blackColor];
        textFieldNormal.font = [UIFont systemFontOfSize:17.0];
        textFieldNormal.placeholder = @"";
        textFieldNormal.backgroundColor = [UIColor whiteColor];
        textFieldNormal.autocorrectionType = UITextAutocorrectionTypeNo;    // no auto correction support

        textFieldNormal.keyboardType = UIKeyboardTypeDefault;   // use the default type input method (entire keyboard)
        textFieldNormal.returnKeyType = UIReturnKeyDone;

        textFieldNormal.clearButtonMode = UITextFieldViewModeWhileEditing;  // has a clear 'x' button to the right

        textFieldNormal.tag = kViewTag;     // tag this control so we can remove it later for recycled cells

        textFieldNormal.delegate = self;    // let us be the delegate so we know when the keyboard's "Done" button is pressed

        // Add an accessibility label that describes what the text field is for.
        [textFieldNormal setAccessibilityLabel:NSLocalizedString(@"NormalTextField", @"")];
    }  
    return textFieldNormal;
}

Example of [UITextField UITextBorderStyleBezel].

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

UITextField *noRoundFirst = [[UITextField alloc] initWithFrame:CGRectMake(10, 160, labelWidth, labelHeight)];
noRoundFirst.borderStyle = UITextBorderStyleBezel;
noRoundFirst.backgroundColor = [UIColor whiteColor];
[self.view addSubview:noRoundFirst];
[noRoundFirst release];

UITextField UITextBorderStyleBezel example.
  self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 120.0f, 25.0f)];
  self.textField.returnKeyType = UIReturnKeyDone;
  self.textField.placeholder = @"Writer";
  self.textField.borderStyle=UITextBorderStyleBezel;
  [self.textField addTarget:self
                    action:@selector(textFieldDone:)
          forControlEvents:UIControlEventEditingDidEndOnExit];    
  [self addSubview: self.textField];

End of UITextField UITextBorderStyleBezel example article.