Add bottom line to view in SwiftUI / Swift / Objective-C / Xamarin

前端 未结 22 2370
自闭症患者
自闭症患者 2020-11-27 09:19

I would like to keep the border at the bottom part only in UITextField. But I don\'t know how we can keep it on the bottom side.

Can you please advise m

22条回答
  •  心在旅途
    2020-11-27 09:54

     extension UITextField {  
      func setBottomBorder(color:String) {
        self.borderStyle = UITextBorderStyle.None
        let border = CALayer()
        let width = CGFloat(1.0)
        border.borderColor = UIColor(hexString: color)!.cgColor
        border.frame = CGRect(x: 0, y: self.frame.size.height - width,   width:  self.frame.size.width, height: self.frame.size.height)
        border.borderWidth = width
        self.layer.addSublayer(border)
        self.layer.masksToBounds = true
       }
    }
    

    and then just do this:

    yourTextField.setBottomBorder(color: "#3EFE46")
    

提交回复
热议问题