Sunday, June 21, 2015

Adding a radial gradient

Have you used UIAlertController?  Have you ever made your own?  Well, I have.  This blog will not be able how to make your own UIAlertController; instead, it will be about a little known detail that makes the UIAlertController look the way it does.

If you open up a UIAlertView (the predecessor to UIAlertController) in the View Debugging while you run your app, it will not appear.  Therefore use UIAlertController and it will appear.  Did you know that UIAlertControllers have a radial gradient above it?  It is difficult to tell since the view debugging does NOT reveal this gradient.  Instead it just says that the UIAlertController is White.  But it is more than that.  It is partially transparent and there is a Radial gradient which makes it look like there is a spot light on it.  Very subtle yes I know.

But how do you do that?  How do you make the radial gradient?  The secret word is CGContextDrawRadialGradient

Take a look at my github project and see how I have used it with IBDesignables and IBInspectables.  I used the IBInspectables to learn what each value of CGContextDrawRadialGradient actually does and ran it through IBDesignables to render it as I modify the values.

No comments:

Post a Comment