嗨我想在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