Hacker News new | ask | show | jobs
by stuartjmoore 5048 days ago
I haven't tried it, but you should be able to set the cornerRadius of the layer (a CALayer) of the main window. That would apply it to all subviews.
3 comments

This works, but setting the cornerRadius property kills performance. It's preferable to overlay an image with black corners or to bake the black corners into your art assets.
CALayer masking on the main window will cause the entire window to be rendered offscreen, which isn't going to be usable for even the most basic app on a real device.

I'd recommend either baking the corners into your art assets (for your NavigationBar, Toolbar, TabBar backgrounds), or overriding drawRect on the NavigationBar and Toolbar and adding a clip. Most apps I've worked on end up demanding a custom NavigationBar and Toolbar anyway, so there's not much reason not to do this.

If a truly abstract solution was really necessary (i.e. "I need 4 round corners absolutely everywhere, and I don't have custom art assets"), I think the easiest way would be to create four "round corner" image views and add them to a subview of the application delegate's UIWindow. This would also be much faster than masking the layer, as it'd create four small GPU-accelerated blend areas rather than one giant offscreen view to upload every frame. The main drawback (and the reason why I suggest the art asset version instead) is that orientation and bounds changes have to be handled manually for added subviews of UIWindow.

I just confirmed that this does work. Note, however, that you'll also need to set clipsToBounds to YES on the window.