Timo Cengiz Timo Cengiz - 1 year ago 87
iOS Question

Button looking really weird on storyboard

I am trying to fix a cool looking button but for some reason it is looking really weird in the storyboard. Anybody knows why?

enter image description here

That is how it looks when i use the picture i have as the background

enter image description here

And this is how it looks when i set the picture i have as image.

This is the image that i am using for the button:

enter image description here

So my question is basically is there anyway to use this image to fill out the whole button area so it looks good?

Thank you


When i used andres code:

enter image description here

Answer Source

i guess you have to set this up in code like this:

let insets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)
let image = UIImage(named: "bt_bg")?.resizableImageWithCapInsets(insets)
button.setBackgroundImage(image, forState: .Normal)

the insets specify which parts of the image to preserve (in this case 10 points to preserve the rounded corners on the left and right side of the image) and which to repeat (everything within 10 points from the left and the right).

hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download