[英]Xcode 7: Shadow does NOT show around UIView in Interface Builder
I want to see my UIView with added shadow like the example image below in storyboard. 我想在故事板中看到我的UIView添加阴影,如下面的示例图像。 Unfortunately, there isn't an existing option to set it. 不幸的是,没有现成的选项来设置它。 Is there a way to set up the shadow using keypath so I can view the shadow in storyboard? 有没有办法使用keypath设置阴影,以便我可以在故事板中查看阴影?
EDIT: 编辑:
I have tried to render a shadow with the following code: 我试图使用以下代码渲染阴影:
import Foundation
import UIKit
@IBDesignable
class ShadowedView: UIView {
override func layoutSubviews() {
super.layoutSubviews()
let shadowPath = UIBezierPath(rect: self.bounds)
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOffset = CGSize(width: 0, height: 0.5)
self.layer.shadowOpacity = 0.2
self.layer.shadowPath = shadowPath.CGPath
self.clipsToBounds = false
}
}
@IBDesignable
allowed me to see the changes immediately, but the shadow still is not present in the storyboard. @IBDesignable
允许我立即看到更改,但故事板中仍然没有阴影。 Here is a screenshot of it: 这是它的截图:
And the result should be the example image. 结果应该是示例图像。 Thank you! 谢谢!
You would need to override drawRect:
or prepareForInterfaceBuilder
depending on your needs. 您需要根据需要覆盖drawRect:
或prepareForInterfaceBuilder
。 You can read more in the docs : https://developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/Chapters/CreatingaLiveViewofaCustomObject.html 您可以在以下文档中阅读更多内容: https : //developer.apple.com/library/ios/recipes/xcode_help-IB_objects_media/Chapters/CreatingaLiveViewofaCustomObject.html
Bottom line : you will have to add the code you posted in the drawRect:
method in your custom view annotated as IBDesignable
and Interface Builder will render it for you. 结论:您必须在自定义视图中添加您在drawRect:
方法中发布的代码,注释为IBDesignable
,Interface Builder将为您呈现它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.