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

前端 未结 22 2308
自闭症患者
自闭症患者 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:47

    ** Here myTF is outlet for MT TEXT FIELD **

            let border = CALayer()
            let width = CGFloat(2.0)
            border.borderColor = UIColor.darkGray.cgColor
            border.frame = CGRect(x: 0, y: self.myTF.frame.size.height - width, width:  self.myTF.frame.size.width, height: self.myTF.frame.size.height)
    
            border.borderWidth = width
            self.myTF.layer.addSublayer(border)
            self.myTF.layer.masksToBounds = true
    

提交回复
热议问题