Answers for "add top shadow to uiview swift"

0

how to make box shadow swift

extension UIView {
func dropShadow(color: UIColor, opacity: Float = 0.5, offSet: CGSize, radius: CGFloat = 1, scale: Bool = true) {
    layer.masksToBounds = false
    layer.shadowColor = color.cgColor
    layer.shadowOpacity = opacity
    layer.shadowOffset = offSet
    layer.shadowRadius = radius

    layer.shadowPath = UIBezierPath(rect: self.bounds).cgPath
    layer.shouldRasterize = true
    layer.rasterizationScale = scale ? UIScreen.main.scale : 1
  }
}
Posted by: Guest on June-09-2020
0

add shadow to specific corner of UIView with shadow swift 6 site:stackoverflow.com

let containerV = UIView(frame: CGRect(x: 0, y: 0, width: self.frame.size.width , height: 50))
containerV.clipsToBounds = false
containerV.layer.shadowColor = UIColor.black.cgColor
containerV.layer.shadowOpacity = 1 
containerV.layer.shadowOffset = CGSize(width: -0.5, height: -3.0) 
/* since we dont want shadow at bottom */
containerV.layer.shadowRadius = 2
containerV.layer.shadowPath = UIBezierPath(roundedRect: containerV.bounds, 
cornerRadius: 10).cgPath

let headerLabel  = UILabel()
headerLabel.frame = containerV.bounds
headerLabel.text = "Test Header"
headerLabel.backgroundColor = UIColor.white

headerLabel.clipsToBounds = true
headerLabel.layer.cornerRadius = 10
if #available(iOS 11.0, *) {
        headerLabel.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
    } else {
        // Fallback on earlier versions
    }
containerV.addSubview(headerLabel)
Posted by: Guest on April-07-2021

Code answers related to "add top shadow to uiview swift"

Code answers related to "Swift"

Browse Popular Code Answers by Language