A Banner View for iOS 11+

I needed a way to present non-modal alerts inside an app I’m working on and wanted to use a banner system that’s a bit like what Tweetbot1 does. I ended up writing a UIView subclass called BannerView that I’ve open sourced for anybody to use.

The banner view uses the new safe area layout guides introduced in iOS 11 to lay itself out correctly when navigation bars are present. The top of the banner expands to fill the top safe area which looks really cool on an iPhone X2:

The appearance of the banner is easily customised and an optional icon can be displayed alongside the message. There’s support for a swipe-to-dismiss gesture baked in too.

There are a few minor issues but they shouldn’t be too hard to fix. The banner doesn’t quite resize properly if the phone’s rotated and things get a bit funky if the banner’s embedded inside a navigation bar with prefersLargeTitles = true. Oh, and there’s no built in way to perform an action when the user taps the banner although you could accomplish that by attaching a UITapGestureRecognizer to the view.

Again, you can get BannerView from here. It’s licensed under an MIT license.


  1. I haven’t used Tweetbot for almost a year but I know it used to have these banners. ↩︎

  2. At least, it does in the simulator. I can only imagine what it looks like on an actual device. ↩︎