Skip to content

Instantly share code, notes, and snippets.

@ku
Last active November 8, 2023 10:55
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ku/3e965b5d99c02e03d45dfce0acdc8731 to your computer and use it in GitHub Desktop.
Save ku/3e965b5d99c02e03d45dfce0acdc8731 to your computer and use it in GitHub Desktop.
dump SF symbols as PNG
import UIKit
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
var image = UIImage(systemName: "plus.circle.fill")!
image = image.withTintColor(.init(
red: 0x37/255.0,
green: 0xc6/255.0,
blue: 0x59 / 255.0,
alpha: 1.0), renderingMode: .alwaysOriginal)
let updatedConfiguration = UIImage.SymbolConfiguration(weight: .bold)
let sizes: [CGFloat] = [120, 152, 167, 180, 1024]
sizes.forEach { x in
let v = UIImageView(image: image)
v.preferredSymbolConfiguration = updatedConfiguration
v.frame = CGRect(x: 0, y: 0, width: x, height: x)
v.contentMode = .scaleAspectFit
v.tintColor = .black
let scale = 1
UIGraphicsBeginImageContextWithOptions(v.layer.frame.size, false, CGFloat(scale))
v.layer.render(in: UIGraphicsGetCurrentContext()!)
let viewImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
let data = viewImage.pngData()
let documentsDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as! String
let n = Int(x)
let writePath = URL(fileURLWithPath: documentsDir + ("/\(n)-\(n).png"))
print(writePath)
try! data?.write(to: writePath)
view.addSubview(v)
self.view = view
}
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
@vermont42
Copy link

Thanks for sharing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment