ios - UINavigationController 堆栈中的阴影
问题描述
在UINavigationController
堆栈中,如何更改最顶层 viewController 的图层属性,例如.view.layer.shadowRadius
?
换句话说,我需要更改默认的 shadowRadius,它在滑回RootViewController
.
非常感谢。
编辑:问题不在于创建属性,而是在堆栈中找到正确的视图/接受它作为替代的 shadowRadius。
解决方案
最好的方法是在你的类中添加这个扩展,在你的类的末尾添加扩展,并将阴影和角半径添加到任何视图以及导航控制器:)
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
}
}
}
}
推荐阅读
- elasticsearch - 找出是否有任何聚合将有桶而不进行聚合
- asp.net - 在同一个端口上运行 Angular 和 ASP.NET Web API
- node.js - npm 包到 ssh 到没有密码的服务器 nodejs
- c# - 如何在 ASP.NET Core 2.1 应用程序中注册 Typed HttpClient
- windows - Docker 使用没有任何镜像的内存
- javascript - `DatePickerInput` 的“className”属性`
- django - Django获取字段值的属性(外键)
- java - 无法通过命令行运行 java 代码。尝试通过命令行更改 CLASSPATH 并设置新的 CLASSPATH
- xcode - Xcode 存档,为什么 EnterPrise ipa 的大小比 AppStore 的小?
- html - 如何使用 html css 设置纸张大小?