Resizing image using capinsets

前端 未结 2 1640
無奈伤痛
無奈伤痛 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

提交回复
热议问题