简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM