UINavigationController堆栈中的阴影

时间:2019-04-26 10:22:48

标签: ios swift uinavigationcontroller

UINavigationController堆栈中,如何更改最高的viewController的图层属性,例如.view.layer.shadowRadius

换句话说,我需要更改默认的shadowRadius,它将在滑动回RootViewController时分隔可见的viewControllers。

非常感谢。

编辑:问题不是创建属性,而是在堆栈中找到正确的视图/接受替代的shadowRadius。

1 个答案:

答案 0 :(得分:0)

最好的方法是在班级中添加此扩展名,在班级末尾添加扩展名,并将阴影以及拐角半径添加到任何视图以及导航控制器中:)

extension UIView {


@IBInspectable
var cornerRadius: CGFloat {
    get {
        return layer.cornerRadius
    }
    set {
        layer.cornerRadius = newValue
    }
}

@IBInspectable
var borderWidth: CGFloat {
    get {
        return layer.borderWidth
    }
    set {
        layer.borderWidth = newValue
    }
}

@IBInspectable
var borderColor: UIColor? {
    get {
        if let color = layer.borderColor {
            return UIColor(cgColor: color)
        }
        return nil
    }
    set {
        if let color = newValue {
            layer.borderColor = color.cgColor
        } else {
            layer.borderColor = nil
        }
    }
}

@IBInspectable
var shadowRadius: CGFloat {
    get {
        return layer.shadowRadius
    }
    set {
        layer.shadowRadius = newValue
    }
}

@IBInspectable
var shadowOpacity: Float {
    get {
        return layer.shadowOpacity
    }
    set {
        layer.shadowOpacity = newValue
    }
}

@IBInspectable
var shadowOffset: CGSize {
    get {
        return layer.shadowOffset
    }
    set {
        layer.shadowOffset = newValue
    }
}

@IBInspectable
var shadowColor: UIColor? {
    get {
        if let color = layer.shadowColor {
            return UIColor(cgColor: color)
        }
        return nil
    }
    set {
        if let color = newValue {
            layer.shadowColor = color.cgColor
        } else {
            layer.shadowColor = nil
        }
    }
}
}
相关问题