2013-11-21 107 views
24

我有一个UITextField,我试图使UITextField边框不可见,以便背景和UITextField具有相同的颜色,并且会有无缝的外观。但问题是我也使用占位符,并且有一个我无法删除的边框。我已经尝试过了:如何隐藏UITextField边框?

textOption.borderStyle = UITextBorderStyleNone; 
textOption.layer.borderWidth = 0; 

它没有工作。你能帮我解决吗?我仍然可以看到UITextField的边框。 fyi:我使用的UITextView没有这个问题=>在UITextViews中没有占位符。

+0

什么约textOption.backgroundColor = [的UIColor clearColor]; ... – AntonijoDev

回答

19

只要使用这个..

textOption.borderStyle = UITextBorderStyleNone; 
[textOption setBackgroundColor:[UIColor clearColor]]; 
0
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]; 
5

如果您使用的界面生成器或故事板,您可以选择文本框,去属性检查器中的选项卡,在选项下边框样式,你有4种风格选择,第一个是没有边界。

如果在代码中这样做,这应该工作

textOption.borderStyle = UITextBorderStyleNone; 
[textOption setBackgroundColor:[UIColor clearColor]]; 
62

如果要删除文本框边框,您可以直接与界面生成器做: enter image description here

+0

不适合我!它也可以是别的吗?谢谢! – Ron

+1

....和编程式:txtIMugName.borderStyle = .none –

+2

它不适用于iOS 11 –

1

你必须只设置边框样式无

textFieldName.borderStyle = UITextBorderStyleNone; 
10

在斯威夫特这个工作对我来说:

passwordTextField.borderStyle = UITextBorderStyle.none 
1

夫特4:

yourTextfield.borderStyle = .none 
+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [来自评论](/ review/low-quality-posts/18386806) – Deep