I would like to add a shadow effect to my UITextField currently what I\'m achieving is this:
As you can see the shadow is not rounded in the corners. My code:
extension UITextField {
func addShadowToTextField(color: UIColor = UIColor.gray, cornerRadius: CGFloat) {
self.backgroundColor = UIColor.white
self.layer.masksToBounds = false
self.layer.shadowColor = color.cgColor
self.layer.shadowOffset = CGSize(width: 0, height: 0)
self.layer.shadowOpacity = 1.0
self.backgroundColor = .white
self.layer.cornerRadius = cornerRadius
}
}
Add Extension and Usage:
dateTxtFld.addShadowToTextField(cornerRadius: 3)
dateTxtFld.addShadowToTextField(color: UIColor.blackColor, cornerRadius: 3)