2013-03-01 113 views

回答

44

您可以使用此:

yourTextField.layer.borderColor=[[UIColor blackColor]CGColor]; 

yourTextField.layer.borderWidth=1.0; 

记得导入#import <QuartzCore/QuartzCore.h>在你的.h文件中

你也可以指定你的RGB值。

yourTextField.layer.borderColor=[[UIColor colorWithRed:178.0f/255.0f green:178.0f/255.0f blue:178.0f/255.0f alpha:1.0] CGColor]; 

注:您需要设置两个值与iOS开始7

更新为SWIFT 2.3

yourTextField.layer.borderColor = UIColor.blackColor().CGColor 
yourTextField.layer.borderWidth = 1.0 

OR

yourTextField.layer.borderColor = UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0).CGColor 

更新迅速3.1.1

yourTextField.layer.borderColor = UIColor.black.cgColor 
yourTextField.layer.borderWidth = 1.0 

OR

yourTextField.layer.borderColor = UIColor(red: 178.0/255.0, green: 178.0/255.0, blue: 178.0/255.0, alpha: 1.0).cgColor 
+3

似乎无法在IOS7上工作 – Jeef 2014-03-19 15:13:04

+2

它仅适用于borderWidth。即使在iOS6中也必须提供borderWidth。它也适用于iOS7。 – KDeogharkar 2014-03-20 04:03:09

+0

与此搏斗约10分钟!最后,我似乎没有将textField连接到插座( – trickster77777 2014-10-30 16:23:31

11
#import <QuartzCore/QuartzCore.h> 

下面的代码用于更改文本字段的边框颜色

textField.layer.borderWidth = 2.0f; 
textField.layer.borderColor = [[UIColor redColor] CGColor]; 
textField.layer.cornerRadius = 5; 
textField.clipsToBounds  = YES; 

对于SWIFT:当我搜索文本框的边框颜色改变我力发现后,所以我张贴,否则,我会没有

textField.layer.borderColor = UIColor.redColor().CGColor; 
+0

txt_field.layer.borderColor = UIColor.redColor()。CGColor //对于Swift – 2016-03-30 14:08:44