Stretching art for buttons and views

The stretching of UIViews in Interface Builder works and is totally cool.  You put in the percentages of the region you want to be stretchable so you can have a tiny little square work as the background for a great big dialog.

But while the fields remain there, it doesn’t work for UIButtons.  Since they do their own drawing thing with the states and the glavin, stretching is in a totally different place.  You modify the image directly, not the view.

UIImage *tIdentifierButtonImage = [m_IdentifierButton backgroundImageForState:UIControlStateNormal];
tIdentifierButtonImage = [tIdentifierButtonImage stretchableImageWithLeftCapWidth:80.0f topCapHeight:12.0f];
[m_IdentifierButton setBackgroundImage:tIdentifierButtonImage forState:UIControlStateNormal];

Numbers are pixels here, not normalized percentages in contentStretch.

Tags: ,

About Graham Smallwood

My name is Graham Smallwood, and I have over 10 years of programming experience and 6 published million-selling games. I work full time as an iOS developer, and am always looking for contract work to do in my spare time.