# Swift 实现 横线样式的输入框

- Link: https://www.ixiqin.com/2017/08/15/swift-dash-style-of-input-box/
- Published: 2017-08-15T21:37:41+08:00
- Author: 白宦成

输入框样式的输入框是我们在做项目时经常会使用到的。除了引用一些第三方的库来实现这样
的样式，我们还可以通过代码来实现这样的效果。
  具体的代码如下

    ```swift
    func setBottomBorder(textField:UITextField){
            let border = CALayer()
            let width = CGFloat(1.0)
            border.borderColor = UIColor.white.cgColor
            border.frame = CGRect(x: 0, y: textField.frame.size.height - width, width:  textField.frame.size.width, height: textField.frame.size.height)
            border.borderWidth = width
            textField.layer.addSublayer(border)
            textField.layer.masksToBounds = true
        }
    ```

调用时，使用

    ```swift
    @IBOutlet weak var firstPagePhone: UITextField!
     setBottomBorder(textField: firstPagePhone)
    ```

 

## Comments

### By: Mr.Li

- Link: https://www.ixiqin.com/2017/08/15/swift-dash-style-of-input-box/#comment-15
- Published: 2017-08-21T22:45:42+08:00

同为码农，过来鼓励一下
