如何设置UITextfield的边框样式
问题描述:
如何以编程方式设置UITextField
的边框样式?如何设置UITextfield的边框样式
我创造我的文本字段像这样:
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];
答
试试这个
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];
仅供参考
答
您可以使用Quartzcore和图层属性。
sometextfield.layer.borderWidth = 1;
sometextfield.layer.borderColor = [[UIColor redColor] CGColor];
我必须记住要将QuartzCore添加到您的项目并将其导入到您想要使用它的地方。
答
[pTxtTithiTime.layer setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
[pTxtTithiTime.layer setBorderWidth:0.8];
//圆角部分,在那里你指定你的观点的角球弧度IUS:
pTxtTithiTime.layer.cornerRadius = 5;
pTxtTithiTime.clipsToBounds = YES;
答
你可以的UITextField编程方式是这样的:
UITextField *txtField = [[UITextField alloc]initWithFrame:CGRectMake(10, 260, 280, 30)]; // your required coordinate
txtField.delegate = self;
txtField.placeholder = @"My TextField";
txtField.borderStyle = UITextBorderStyleNone;
txtField.keyboardType = UIKeyboardTypeDefault;
txtField.backgroundColor = [self setBackGroundColorOnButton];
txtField.layer.cornerRadius = 5.0;
答
从以下四个任何人都可以通过编程的方式使用,
[textField setBorderStyle:UITextBorderStyleNone];
[textField setBorderStyle:UITextBorderStyleLine];
[textField setBorderStyle:UITextBorderStyleBezel];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
其中文本框是UITextField
答
我知道,问题是关于Obj-C,但我来到这里是为了Swift。而在斯威夫特,它的完成这样的:
txt.backgroundColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0);
txt.borderStyle = UITextBorderStyle.RoundedRect
let myColor : UIColor = UIColor(red: 0.9, green: 0.9, blue: 0.9, alpha: 1.0);
txt.layer.borderWidth = 3;
txt.layer.borderColor = myColor.CGColor;
这将设置一个自定义背景色,并在相同的颜色(隐藏边框,但仍然有文本和文本框边界之间一些填充边界