嗨我想在UITextField下得到阴影。我已经对UIView进行了如下扩展。但是,如果切断TextField的一半用户界面。uiview下没有阴影
如何在UIView/UITextField下添加阴影?
public extension UIView {
func installShadow() {
self.layer.masksToBounds = false
self.layer.backgroundColor = UIColor.white.cgColor
self.layer.shadowColor = UIColor.lightGray.cgColor
self.layer.shadowRadius = 5
self.layer.shadowOpacity = 1
self.layer.shadowOffset = CGSize(width: 0, height: 1)
let shadowPath = CGPath(ellipseIn: CGRect(x: self.frame.origin.x,
y: self.frame.origin.y,
width: self.frame.size.width,
height: self.frame.size.height),
transform: nil)
self.layer.shadowPath = shadowPath
}
}
您正在使用'CGPath(ellipseIn:'这是故意的吗? –
试试这个'self.layer.shadowPath = UIBezierPath(rect:self.bounds).cgPath' –
你需要显示一个图像,你希望看到结果。 – DonMag