iOS 프로젝트에 그림자가있는 사용자 정의 UIView를 만들었습니다. 목표는보기의 배경과 동일한 그래디언트를 그림자에 적용하는 것입니다.UIView 그림자 그라디언트
다음은 현재의 단색 그림자를 보여주는 예입니다.
은 아래의 코드에 UIView의 하위 클래스를 통해 이루어집니다 :override func layoutSubviews() {
let gradientLayer = layer as! CAGradientLayer
gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor]
gradientLayer.startPoint = CGPoint(x: startPointX, y: startPointY)
gradientLayer.endPoint = CGPoint(x: endPointX, y: endPointY)
layer.cornerRadius = cornerRadius
layer.shadowColor = shadowColor.cgColor
layer.shadowOffset = CGSize(width: shadowX, height: shadowY)
layer.shadowRadius = shadowBlur
layer.shadowOpacity = 1
let inset: CGFloat = bounds.width * 0.05
layer.shadowPath = UIBezierPath(roundedRect: bounds.insetBy(dx: inset, dy: 0.0), cornerRadius: cornerRadius).cgPath
}
내가 두 번째 그라디언트 레이어를 만들고 그림자에 마스킹하지만 운이 없었다 주변에 연주되었다. 저를 올바른 방향으로 가르쳐주십시오!