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.
I dont know why is it breaking at the corners. Help me to fix my text field like the image attached below.
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.
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 .
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];
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With