ch1maera
ch1maera

Reputation: 1447

Adding Shadow to a UIBarButton

Is it possible to add a background shadow to a UIBarButton? I'm using the generic bar button outlet in the storyboard and haven't hardcoded it in and haven't found any answer on StackOverflow or elsewhere that describes how it could be done.

Upvotes: 0

Views: 820

Answers (1)

Josh Homann
Josh Homann

Reputation: 16347

The shadows in UIKit come from the layer (an instance of CALayer) on UIView. Since UIBarButtonItem is one of the few UI classes that does not inherit from UIView (it inherits from UIBarItem, which inherits from NSObject) you don't get access to CALayer and the drop shadow. However it is possible to init UIBarButtonItem with a custom UIView. In that case the view is just like any other view and you can set its shadow accordingly.

Upvotes: 2

Related Questions