Craig Grummitt – Before I forget

Discoveries in Swift and iOS development.

Tiled background image in custom UIView class

·

Sometimes you need a repeated or tiled image in your app, often for a background. Something like these rain-drops for example:

Here’s a simple UIView subclass that accepts an image parameter, and renders a repeated tiled image, even in the storyboard:

https://gist.github.com/craiggrummitt/91e9e5527428bc6e69939079865e3a28

It creates a patterned image in a UIColor object, sets this as the current fill, and then fills the view’s rect with this color.

Here’s how it looks in the storyboard:


Comments

One response to “Tiled background image in custom UIView class”

  1. […] recently wrote an article on a simple custom UIView class you can use to tile an image. Unfortunately – this […]

Leave a Reply

Your email address will not be published. Required fields are marked *