Resizing image using capinsets

前端 未结 2 1633
無奈伤痛
無奈伤痛 2020-12-19 15:08

I have setup a button like this:

// Create facebook login button
facebookLoginButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 20, 300,50)];
facebookL         


        
相关标签:
2条回答
  • 2020-12-19 15:51

    Since you are setting the frame of the button explicitly, and since you are creating your own image, you do not need a resizable image. Your button is 300 by 50 so make a 300 by 50 image (along with a 600 by 100 image for a double-resolution device) and set the background image of the button to it.

    However, I'll also give a code example. For the image that you actually give, if you name it FacebookLogin@2x.png so that it is used as the double-resolution image, the value you want to use is resizableImageWithCapInsets:UIEdgeInsetsMake(0,50,0,50). Here is the result:

    enter image description here

    0 讨论(0)
  • 2020-12-19 15:55

    I wrote a script to generate the resizable image with cap insets. Very useful. https://github.com/kejinlu/capimage

    0 讨论(0)
提交回复
热议问题