Custom UIAlertView for iOS

It was a common pattern for iOS developers to create customised dialogs by attaching a subview to a standard UIAlertView. Since iOS7 however, Apple removed this feature and developers are left without a dialog pattern that matches the iPhone UI.

As a solution, I wrote an open source class to create an iOS8-style dialog which can be extended with any UIViews or buttons. The animations and the looks are copied too, and no images or other resources are needed.

You can just grab the open source code from Github now. In this article I will write about the implementation best practices and some background info.

Extend your current AlertView code to support iOS7 and iOS8

To create an AlertView with a custom subview, you probably wrote something similar to this:

And you did probably reset the frame in the delegate method willPresentAlertView too.

This was working on all previous iOS versions. On iOS7 however it will result in an empty dialog. What you have to do therefore is to fork the code here: display a standard UIAlertView on the old devices, and a CustomIOSAlertView on the new ones.

Forking the code is as simple as this:

For the new dialog, you would add something like the following:

Putting these two together, a full solution would look like this:

And that’s it! For the CustomIOSAlertView is a hack-free UIView, you don’t have to add anything to the willPresentAlertView delegate, just keep it as it is. For handling the iOS7 button clicks, you can use code blocks or delegates – please refer to the project’s readme.

How did we end up here?

Apple never officially supported the addSubview method of the UIAlertView. Their approach is to use this dialog only for a small subset of functions, like a plain text input. This is as easy to do as setting the style of the UIView to UIAlertViewStylePlainTextInput.

However, UI/UX designers like to use the dialog pattern for other use cases as well. An example is to show a simple image to the user, or display a progress bar while the user is waiting for a background download to be finished.

Until the previous iOS version the addSubView method worked fine, and developers used it as a best practice for these dialogs patterns. That’s why Apple’s move left app publishers in a bad position: before rolling out the updated version of our apps, in some cases we have to find a completely new user journey.

This is where the CustomIOSAlertView comes handy: we can roll out the iOS7-support quickly (and start up the user experience think thank in the background).

(Free code and source from Github. Opinions, debate: @wimagguc on Twitter.)

j j j

Getting rid of Google Maps

Being dependent on someone else’s technology feels bad. Especially if that someone can an does change it’s pricing from time to time – more so, if those changes could completely bail you out of business. That kind of fear builds mountains – or, for iOS 6 a new Maps service that replaces Google Maps.

Every time I design products where we need to use the Google Maps API, I have a certain feeling: the maps are great, we can estimate the short term costs, but the fact is that we are dependent on one vendor. I’m really glad to see that another player is entering the game now.

That’s the business perspective of course. As a user, I’m simply curious. The first screenshots of Maps are not that great (keep in mind that in Europe, we probably will receive that 3D sugar much much later than users in the US), but by doing my research, I’ve found a really promising fact: the new software is based on the services of C3 Technologies, which is a research lab of the SAAB group.

That means, at least in theory, with this technology creating those high resolution 3D maps might be closer than we think. “Since the high-resolution maps are accurately georeferenced, coordinates can be extracted and used for leading indirect fire such as artillery, as well as close air support targeting.”

And, of course, locating the nearest Starbucks.

j j j

Hacker shine

Updated

Programming used to be a hacker thing: men in black sitting on the floor, bending over a laptop that has some key parts missing (or even wires coming out), and the only source in the dark room at 3 am in the morning is the dim light from the monitor. Nowadays though, programmers get some shine.

Codea is a touch-based programming app for the iPad, that lets developers create games and simulations. Of course, it’s more a toy than a heavy weight development environment (and since the current kit doesn’t support any kind of publishing, the final games will never leave the iPad itselfI was awfully wrong! See below). Not like it’s a big deal, no one will cry over missing out those “amazing things” created with Codea.

So the time is not now, yes, but the damage has been made: as more and more development tools will come out, eventually, programmers will be changing their black bricks into shiny toys – just like journalist did some time ago.

Whoha-hoo.

Update: as @TwoLivesLeft said on Twitter, there is a solution to turn apps made with Codea into native iOS apps, and the code for this is already on Github. One example app in the App Store is Cargo Bot, available for free for iPad.

j j j