简体   繁体   English

如何删除文本框的黑色边框?

[英]How do I remove the black border of a textfield?

I made a textfield in IB with the following settings: 我在IB中使用以下设置创建了文本字段:

  • Borderstyle: RoundRect 边框样式:RoundRect
  • View's BG Color: Black, Opacity: 15% View的BG颜色:黑色,不透明度:15%

The result is that the inside of the field is 15%, but there's a very thin visible border that isn't, and I want that removed. 结果是该字段的内部为15%,但是有一个非常细的可见边框不是,我希望将其删除。 I've tried doing it in code like this: 我试过在这样的代码中这样做:

textField.borderStyle = UITextBorderStyle.None
textField.layer.cornerRadius = 10
textField.layer.borderColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:0.15).CGColor

But this just puts the border on the inside covering the actual textfield. 但这只是将边框放在内部,覆盖了实际的文本字段。

Textfield: 文本域:

在此处输入图片说明

Try to add this: 尝试添加以下内容:

textField.layer.borderWidth = 0

Additionally, from the screenshot, it seems that textField.layer.cornerRadius = 10 is ignored, make sure that your textField property is connected to the actual UITextField . 此外,从屏幕快照中,似乎textField.layer.cornerRadius = 10被忽略了,请确保您的textField属性已连接到实际的UITextField

Swift 3 / Swift 4 迅捷3 /迅捷4

The simplest approach to achieving a border-free textfield is to change the style of the textfield. 实现无边界文本字段的最简单方法是更改​​文本字段的样式。

Steps 脚步

  1. Make a IBOutlet reference to the textfield. 使IBOutlet引用文本字段。
  2. Set the textfield's border style to none. 将文本字段的边框样式设置为无。

Example Code 范例程式码

// Reference
@IBOutlet var tf: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    // Email TextField: no border
    tf.borderStyle = .none
}

The Result 结果

如何在Swift 3中删除文本框边界的图像Swift 4

Swift3 Swift3

passwordTF.layer.borderColor = UIColor.clear.cgColor

For me its working as well as 对我来说,它的工作以及

mobileNumberTF.borderStyle = .none

Try this one 试试这个

self.nameTextField.borderStyle = UITextBorderStyleNone; self.nameTextField.borderStyle = UITextBorderStyleNone;

I've tried several ways to remove the broder by programmatically and other suggested ways but later figured out this is the only way it removes the border from UITextField. 我尝试了几种方法,以编程方式和其他建议的方式删除了broder,但后来发现这是从UITextField删除边框的唯一方法。 Just select in interface builder, Border Style option 只需在界面生成器中选择“边框样式”选项

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM