Search code examples
iphoneobjective-ciosios5uitextfield

UITextField - Rounded corner issue


I bring the issue forward which I face. I am creating a UITextField programmatically as below.

UItextField *mobileNumberField = [[UITextField alloc] initWithFrame:CGRectMake(10, 195, 300, 41)];
mobileNumberField.delegate = self;
mobileNumberField.borderStyle = UITextBorderStyleRoundedRect;
[mobileNumberField.layer setCornerRadius:14.0f];
mobileNumberField.placeholder = @"Mobile Number";
[self.paymentsHomeView addSubview:mobileNumberField];

The output is the attached image.

enter image description here

I dont know why is it breaking at the corners. Help me to fix my text field like the image attached below.

enter image description here


Solution

  • Just remove this line...

    mobileNumberField.borderStyle = UITextBorderStyleRoundedRect;
    

    and add this code also..

        [mobileNumberField setBackgroundColor:[UIColor whiteColor]];
        [mobileNumberField.layer setBorderColor:[UIColor grayColor].CGColor];
        [mobileNumberField.layer setBorderWidth:1.0];