I’m making an app where I use UIEdgeInsetsMake for resizableImageWithCapInsets, but I don’t understand how does it works exactly, UIEdgeInsetsMake has 4 arguments:
- Top
- Left
- Bottom
- Right
But they’re floats so I don’t know how to set that to an image, thanks! 😀
According to the documentation:
So you only need to use the amount of pixels you want to make unstretchable in the values of the
UIEdgeInsetsMakefunction.Say you have an image of 21×50 points (21×50 pixels in standard definition, 42×100 pixels in Retina "@2x" definition) and want this image to be horizontally stretchable, keeping the 10 points on the left and on the right untouched when stretching the image, but only stretch the 1-point-wide band in the middle. Then you will use
UIEdgeInsetsMake(0,10,0,10).Don’t bother that they are floats (that’s useful for subpixelling resizing for example, but in practice you will probably only use integers (or floats with no decimal parts)
Be careful, this is an iOS5+ only method, not available prior iOS5. If you use pre-iOS5 SDK, use
stretchableImageWithLeftCapWidth:topCapHeight:instead.[EDIT] Some tip I use since some time, as I never remember in which order the fields of the
UIEdgeInsetsstructure are — and in which order we are supposed to pass the arguments toUIEdgeInsetsMakefunction — I prefer using the "designated inits" syntax like this:Or when an explicit cast is needed:
I find it more readable, especially to be sure we don’t mix the different borders/directions!