Home > Net >  iOS UIButton: how to stretch the background image so it fits the button width?
iOS UIButton: how to stretch the background image so it fits the button width?

Time:01-04

Let's say I have this sprite for a UIButton:

enter image description here

I would like to know how I can stretch its center, so the button may look like this for a smaller button:

enter image description here

Or like this for a bigger one:

enter image description here

Thank you for your help!

CodePudding user response:

you can use background-size: 100% 100%; which will stretch image and mess up proportions or background-size: cover; which will scale image, preserve proportions and crop the image

enter image description here

  •  Tags:  
  • Related