Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 865
iOS Avatar asked Dec 05 '12 05:12

iOS


People also ask

Why are rounded corners everywhere?

Rounded Corners and When to Use ThemRounded corners evoke warmth and trust. Many call them “friendly rectangles” for this reason. This is exactly why many call-to-action buttons (a.k.a. buy-now or sign-up buttons) are designed this way. It makes customers feel safe about doing business with a brand.

How do you round the corners of a view?

You can give it round corners by changing the cornerRadius property of the view's layer . and smaller values give less rounded corners. Both clipsToBounds and masksToBounds are equivalent. It is just that the first is used with UIView and the second is used with CALayer .


2 Answers

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]; 
like image 66
Paras Joshi Avatar answered Oct 15 '22 18:10

Paras Joshi


Update your like below.

    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]; 
like image 31
Paramasivan Samuttiram Avatar answered Oct 15 '22 16:10

Paramasivan Samuttiram