The stretch portion of the image is longer than 1px

I would like to create a UIButton that uses a stretchable image as a background image, for example, that I can easily resize the button for different labels, etc.

So, I created the following code that works fine:

UIImage *bgImage = [[UIImage imageNamed:@"Button-Template.png"]stretchableImageWithLeftCapWidth:2 topCapHeight:2];
UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
loginButton.frame = CGRectMake(180, 280, 112, 40);
[loginButton setBackgroundImage:bgImage forState:UIControlStateNormal];
// some more stuff

Now here's the catch: the iPhone SDK assumes that the stretchable part of the image is exactly one pixel wide, which is not the case in my image because I want to create a pattern that needs to be repeated every two pixels (so 2 โ€‹โ€‹pixels is one pattern). I did not find information in the documents about whether it is possible to change the width of the expandable part (in my case 2 instead of 1), does anyone know how to do this or how I could achieve my goal using a workaround? Writing the stretch part in my opinion seems like a bit distant sample right now (although I may have to get back to that).

Thank!

+3
source share
2 answers

API 2 . .

0

iOS 5.0 resizableImageWithCapInsets:

UIImage

iOS >= 5.0, .

+3

Source: https://habr.com/ru/post/1768203/


All Articles