1

I want a view with some shadow and corner radius the problem i have when i have shadow the corner radius is not available i set masktobound to false and i have added this code

  func setShadow() {
    cardCBView.layer.cornerRadius = 10
    cardCBView.layer.borderWidth = 1.0
    cardCBView.layer.borderColor = #colorLiteral(red: 0.8980392157, green: 0.8980392157, blue: 0.8980392157, alpha: 0)
    cardCBView.layer.shadowColor = UIColor.black.cgColor
    cardCBView.layer.shadowOffset = CGSize.zero
    cardCBView.layer.shadowOpacity = 0.2
    cardCBView.layer.shadowRadius = 4.0
 }

i have result like image : with masktobound off with masktobound off

with masktobound = on with masktobound = on

when i put different color for bordercolor when i put different color for bordercolor

how can i have shadow and radius corner ?

any help is appreciated

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
tamtoum1987
  • 1,957
  • 3
  • 27
  • 56
  • 1
    You cannot clip to the corner radius and cast a shadow from the same view. They are opposites. See my discussion here: https://stackoverflow.com/a/57351560/341994 – matt May 25 '20 at 12:02

2 Answers2

1

There are three steps through which you can achieve both shadow and corers

  1. Add one more view behind CardCB View with same frame or constraints
  2. Add corners to this view ad set clipToBounds = true
  3. Give your main view shadow and set its clipToBounds = false
Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
  • 2
    This is correct but not new. Your duty is, rather than to repeat this info, to find a duplicate (there are many) and vote to close. – matt May 26 '20 at 13:38
-1

You should set

clipsToBounds = true
mmm
  • 260
  • 4
  • 21