12

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

Jordan H
  • 52,571
  • 37
  • 201
  • 351
  • If you have a use case for why your popovers should look different from everyone else's, I suggest filing an enhancement request with Apple. The shadow effect is drawn by the UIPopoverPresentationController but you don't get any way to intervene or customize its behavior. – matt Sep 20 '15 at 17:30
  • There is no API for what you want. Create your own "popover" class with no shadow if that's what you need. – rmaddy Sep 20 '15 at 17:43
  • @Joey, have you figure out anything, do not you think my answer is right? – Julian Jan 20 '16 at 11:54

2 Answers2

10

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;
}
Nishant
  • 12,529
  • 9
  • 59
  • 94
  • 3
    Strangely, the color seems to be the only property you can change. I tried also changing the other shadow properties like radius, opacity, etc to no avail – Kyle Redfearn May 11 '17 at 16:37
2

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")
}
trishcode
  • 3,299
  • 1
  • 18
  • 25