【发布时间】:2018-05-21 02:23:42
【问题描述】:
我正在尝试通过界面生成器为某些视图添加阴影。我似乎无法让阴影影响我的观点。我查看的所有资源都指向相同的代码,所以我不确定我做错了什么。
界面生成器
接口生成器扩展代码
import Foundation
import UIKit
extension UIView {
//cut irrelevant code for SO Question
@IBInspectable
var masksToBounds: Bool {
get {
return layer.masksToBounds
}
set {
layer.masksToBounds = newValue
}
}
// Shadow handling
@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
}
}
}
@IBInspectable
var shadowOpacity: Float {
get {
return layer.opacity
}
set {
layer.opacity = newValue
}
}
@IBInspectable
var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowRadius = newValue
}
}
@IBInspectable
var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set {
layer.shadowOffset = newValue
}
}
}
视图布局
这是结果
【问题讨论】:
-
500 点对于阴影半径来说太大了。你试过用 5 代替吗?
-
@TylerTheCompiler 是的,5 和 500 产生相同的结果
标签: ios swift xcode interface-builder