Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove shadow behind popovers on iOS 9?

In iOS 8, popovers had no shadow. Now in iOS 9, there is a very heavy and far reaching shadow that can look less than desirable on pure white backgrounds. How can that shadow be removed, and instead add a thin light gray line around the popover? Or at least reduced or made lighter.

This occurs when showing action sheets, presenting a view controller using the .Popover UIModalPresentationStyle, and perhaps in other contexts.

Popover segue: enter image description here

Action sheet:

UIActionSheet(title: "Title", delegate: nil, cancelButtonTitle: "Cancel", destructiveButtonTitle: "Destroy").showInView(sender as! UIView)

enter image description here

like image 950
Jordan H Avatar asked Sep 20 '15 17:09

Jordan H


2 Answers

You can make your own custom popover background using UIPopoverBackgroundView

In the initWithFrame of your UIPopoverBackgroundView implementation, you can use a [UIColor clearColor for the drop shadow.

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.layer.shadowColor = [[UIColor clearColor] CGColor];
    }

    return self;
}
like image 156
Nishant Avatar answered Nov 14 '22 09:11

Nishant


Swift 4 version of accepted answer.

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")
}
like image 2
trishcode Avatar answered Nov 14 '22 07:11

trishcode