UITextField Only Top And Bottom Border

后端 未结 11 964
温柔的废话
温柔的废话 2020-12-07 22:46

I currently have a regular border. I would like to only have a top and bottom border.

How do I accomplish this?

Using the UITextField<

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 23:31

    Swift 3: Clean with AutoLayout (I'm using here PureLayout but you can also do it with common NSLayoutConstraint:

    func makeUnderline(for textField: UITextField) {
        let borderLine = UIView()
        borderLine.backgroundColor = UIColor.black
        borderLine.autoSetDimension(.height, toSize: 1)
        textField.addSubview(borderLine)
        borderLine.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets.zero, excludingEdge: .top)
    }
    

提交回复
热议问题