How can I set the border style of a UITextField
programatically?
I am creating my text field like so:
UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)]; tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3]; tfText.textAlignment = UITextAlignmentCenter; [self.view addSubview:tfText]; [tfText release];
You need to set the borderWidth from the UITextField 's layer property. Like: email. layer. borderWidth = 1 .
You can change the TextField border color globally by defining the inputDecorationTheme and then adding the OutlineInputBorder widget. Inside the OutlineInputBorder widget, you can specify which type of border you want to change. for example, enabledBorder , focusedBorder , and so on, and then assign the color.
Try this
UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)]; tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3]; tfText.textAlignment = UITextAlignmentCenter; // Border Style None [tfText setBorderStyle:UITextBorderStyleNone]; [self.view addSubview:tfText]; [tfText release];
For Reference
You can use Quartzcore and the layer properties.
sometextfield.layer.borderWidth = 1; sometextfield.layer.borderColor = [[UIColor redColor] CGColor];
I must remember to add QuartzCore to your project and to import it where you want to use it.
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