在iOS 8中,弹出窗口没有阴影。现在在iOS 9中,有一个非常沉重且影响深远的阴影,在纯白色背景上看起来不太理想。如何去除阴影,而是在弹出窗口周围添加一条细细的灰色线条?或者至少减少或减轻。
当显示动作表,使用.Popover
UIModalPresentationStyle
呈现视图控制器时,以及可能在其他情况下,会发生这种情况。
行动表:
UIActionSheet(title: "Title", delegate: nil, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Destroy").showInView(sender as! UIView)
您可以使用UIPopoverBackgroundView
制作自己的自定义弹出窗口背景
在你的initWithFrame
实现的UIPopoverBackgroundView
中,你可以使用[UIColor clearColor
作为投影。
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.shadowColor = [[UIColor clearColor] CGColor];
}
return self;
}
Swift 4版本接受了答案。
override init(frame: CGRect) {
super.init(frame: frame)
layer.shadowColor = UIColor.clear.cgColor
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}