Lets say we have an image of 600X400 and we want to end up with an new image of 1000X100 which contains the initial image in the centre and transparent space around it. How can I achieve that in code?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Xcode: Is there a way to change line spacing (UI L
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
You create a new image context that is 1000x1000, draw your old image in the middle, then get the new
UIImage
from the context.Make a category on UIImage and try this:
This is the solution in Swift 4 inspired by DrummerB answer:
How to apply:
Features:
A fix for appsunited's answer with better naming convension. To not confuse it the function is mutating or not:
In Swift you can write an extension to UIImage that draws image with insets around it.
Swift 3:
OLD ANSWER: