Swift extension example

后端 未结 8 2137
既然无缘
既然无缘 2020-11-28 01:33

I was originally wanting to know how to make something like this

UIColor.myCustomGreen

so that I could define my own colors and use them th

8条回答
  •  遥遥无期
    2020-11-28 02:20

    Underline text in UITextField

    Used in function ViewDidLoad()

    firstNametext.underlined(0.5)
    

    Extension

    extension UITextField {
    
        func underlined(_ size:Double){
            let border = CALayer()
            let width = CGFloat(size)
            border.borderColor = UIColor.red.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 }
        }
    }
    

提交回复
热议问题