Skip to content
Pascal Arnould By Pascal Arnould Software Engineer III

One way to manage a button visual state in iOS is by setting a different background image for each one of the UIControlState values available: Normal, Disabled, Highlighted and Selected. If all you want is a solid colour background for each specific state, you still have to create separate images, save them as bundle resources and refer back to them in code. This feels like a lot of effort for something which should be a bit more straight forward. However one of the answers to this question on Stack Overflow provided a better solution by creating a 1x1 pixel image programmatically based on a given color. Here's the direct port of the code in C#:

You can then use this utility method to create a button background images and set its visual states as shown below:

Pascal Arnould on Twitter

Pascal Arnould

Software Engineer III

Pascal Arnould

He has over 20 years experience of of implementing complex technology solutions across a number of sectors, and is a passionate advocate of Agile practices, continuous learning and engineering excellence.

Pascal worked at endjin from 2013 - 2015.