xcode 如何隐藏 UITextField 边框?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20116471/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to hide UITextField border?
提问by Javier Calatrava Llavería
I have a UITextField and I am trying to make the UITextField border invisible so that the background and UITextField would have the same color and there would be a seamless look. But the problem is I also use a placeholder and there is a border that I cannot remove. I already tried:
我有一个 UITextField 并且我试图使 UITextField 边框不可见,以便背景和 UITextField 具有相同的颜色并且外观无缝。但问题是我也使用了占位符,并且有一个我无法删除的边框。我已经尝试过:
textOption.borderStyle = UITextBorderStyleNone;
textOption.layer.borderWidth = 0;
It didn't work. Would you please help me on that? I still can see the border of the UITextField. fyi: The UITextView that I use doesn't have this issue => There is no placeholder in UITextViews.
它没有用。你能帮我吗?我仍然可以看到 UITextField 的边框。仅供参考:我使用的 UITextView 没有这个问题 => UITextViews 中没有占位符。
回答by Javier Calatrava Llavería
If you want to remove the textfield border you can do it directly with interface builder:
如果要删除文本框边框,可以直接使用界面构建器进行操作:
回答by Nirav Gadhiya
Just use this..
就用这个..
textOption.borderStyle = UITextBorderStyleNone;
[textOption setBackgroundColor:[UIColor clearColor]];
回答by KOTIOS
In Swift this worked for me :
在 Swift 中,这对我有用:
passwordTextField.borderStyle = UITextBorderStyle.none
回答by Fox5150
Swift 4 :
斯威夫特 4:
yourTextfield.borderStyle = .none
回答by Alexandre Lins
If you are using Interface Builder or Storyboard, you can select the textField, go on the Attributes inspector's tab, under the option Border Style you have 4 styles to chose from, the first one is without border.
如果您使用的是 Interface Builder 或 Storyboard,您可以选择 textField,进入 Attributes inspector 的选项卡,在选项 Border Style 下,您有 4 种样式可供选择,第一个是无边框的。
If doing it in code, this should work
如果在代码中这样做,这应该有效
textOption.borderStyle = UITextBorderStyleNone;
[textOption setBackgroundColor:[UIColor clearColor]];
回答by Alexandre Lins
You have to just set border style None
你只需要设置边框样式无
textFieldName.borderStyle = UITextBorderStyleNone;
回答by codercat
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];