searchcontroller,圆角不工作

时间:2017-04-25 04:17:18

标签: ios swift uiview uisearchbar uicontainerview

enter image description here

enter image description here

enter image description here

此视图的顺序就像这样

 -View Controller

      -Fake shadow view

           -Container view

               -Search Bar

在正常状态下,roundcorner工作正常,但是当我点击它时,会有一些阴影。当我在上面输入内容时,只是视图变为rectengular

1 个答案:

答案 0 :(得分:0)

尝试这个IBDesignable类并从故事板中给出圆角

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
        }
    }
}