Search code examples
iosswiftuiviewuisearchbaruicontainerview

searchcontroller, roundedcorners not working


enter image description here

enter image description here

enter image description here

This view's order is like this

 -View Controller

      -Fake shadow view

           -Container view

               -Search Bar

In normal state, roundedcorner works correctly, but when I click on it, there is some shadow. When I type something on it just the view becomes rectengular


Solution

  • try this IBDesignable class and give rounded corner from story board

    import Foundation
    @IBDesignable class customView: UIView {
        @IBInspectable var cornerRadius: CGFloat = 0 {
            didSet {
                layer.cornerRadius = cornerRadius
            }
        }
    
        @IBInspectable var borderWidth: CGFloat = 0 {
            didSet {
                layer.borderWidth = borderWidth
            }
        }
    
        @IBInspectable var borderColor: UIColor = UIColor.gray {
            didSet {
                layer.borderColor = borderColor.cgColor
            }
        }
    
        @IBInspectable var shadowColor: UIColor = UIColor.gray {
            didSet {
                layer.shadowColor = shadowColor.cgColor
            }
        }
    
        @IBInspectable var shadowOpacity: Float = 1.0 {
            didSet {
                layer.shadowOpacity = shadowOpacity
            }
        }
    
        @IBInspectable var shadowRadius: CGFloat = 1.0 {
            didSet {
                layer.shadowRadius = shadowRadius
            }
        }
    
        @IBInspectable var masksToBounds: Bool = true {
            didSet {
                layer.masksToBounds = masksToBounds
            }
        }
    
        @IBInspectable var shadowOffset: CGSize = CGSize(width: 12, height: 12) {
            didSet {
                layer.shadowOffset = shadowOffset
            }
        }
    }