9

I'm newer with Swift's Apple. I had read an article from Here

But don't know how to do something like that(or just simple don't know how to use resizableImageWithCapInsets with Swift). Please help me to use resizableImageWithCapInsets in Swift

Shruti Thombre
  • 989
  • 4
  • 11
  • 27
lee
  • 7,955
  • 8
  • 44
  • 60

1 Answers1

22

Generic way in Xcode 6.1 is:

  1. Create an UIImage as a variable
  2. Create an insets
  3. Create a new image based on the original image and the insets, and assign it to the original image

var myImage = UIImage(named: "navbar.png")!
let myInsets : UIEdgeInsets = UIEdgeInsetsMake(13, 37, 13, 37)
myImage = myImage.resizableImageWithCapInsets(myInsets)
reVerse
  • 35,075
  • 22
  • 89
  • 84
Daniel Storek
  • 236
  • 2
  • 2
  • in case your original image is small and you don't want to title it then use below function myImage.resizableImage(withCapInsets: myInsets, resizingMode: .stretch) – Waseem Sarwar Mar 30 '20 at 06:06