UIImage and resizableImageWithCapInsets Swift
12,583
Generic way in Xcode 6.1 is:
- Create an UIImage as a variable
- Create an insets
- 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)
Comments
-
lee almost 2 years
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 useresizableImageWithCapInsets
in Swift -
Waseem Sarwar about 4 yearsin case your original image is small and you don't want to title it then use below function myImage.resizableImage(withCapInsets: myInsets, resizingMode: .stretch)