Uda*_*iya 4 uitextfield ios swift
我的代码如下:
    override func viewDidLoad() {
       super.viewDidLoad()
       textField.layer.cornerRadius =             textField.frame.size.height / 2
       textField.layer.borderWidth = 1.0
       textField.layer.borderColor = UIColor(white: 0.5, alpha: 0.3).cgColor
       textField.layer.shadowOpacity = 1
       textField.layer.shadowRadius = 4.0
       textField.layer.shadowColor = UIColor.black.cgColor
    }
但是,我认为有些东西丢失了...
提前致谢!
尝试下面的代码在roundRect文本字段上实现阴影效果。
    //Basic texfield Setup 
    textField.borderStyle = .none
    textField.backgroundColor = UIColor.groupTableViewBackground // Use anycolor that give you a 2d look.
    //To apply corner radius
    textField.layer.cornerRadius = textField.frame.size.height / 2
    //To apply border
    textField.layer.borderWidth = 0.25
    textField.layer.borderColor = UIColor.white.cgColor
    //To apply Shadow
    textField.layer.shadowOpacity = 1
    textField.layer.shadowRadius = 3.0
    textField.layer.shadowOffset = CGSize.zero // Use any CGSize
    textField.layer.shadowColor = UIColor.gray.cgColor
    //To apply padding
    let paddingView : UIView = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: textField.frame.height))
    textField.leftView = paddingView
    textField.leftViewMode = UITextFieldViewMode.always
注意:由于某些原因textField.borderStyle = .none,即使在viewWillLayoutSubviews()或中设置代码也无法生效viewDidLayoutSubviews()。因此,我建议您通过storyBoard textfield设置borderStyle Attributes inspector。
真实设备的输出:
要实现投影效果:(就像其他SO帖子一样)
   textField.layer.borderColor = UIColor.black.withAlphaComponent(0.25).cgColor
   textField.layer.shadowOffset = CGSize(width: 0, height: 3)
   textField.layer.shadowColor = UIColor.black.cgColor //Any dark color
输出:
| 归档时间: | 
 | 
| 查看次数: | 2022 次 | 
| 最近记录: |