Skip to content

Instantly share code, notes, and snippets.

@JunyuKuang
Created October 22, 2019 03:07
Show Gist options
  • Save JunyuKuang/b3da6c487d5248293e876c1e47984776 to your computer and use it in GitHub Desktop.
Save JunyuKuang/b3da6c487d5248293e876c1e47984776 to your computer and use it in GitHub Desktop.
[Mac Catalyst] a helper method that creates NSToolbar image with SF Symbol
//
// UIImage+NSToolbar.swift
// MobileReaderUI
//
// Created by Jonny Kuang on 10/12/19.
// Copyright © 2019 Junyu Kuang <lightscreen.app@gmail.com>. All rights reserved.
//
#if targetEnvironment(macCatalyst)
extension UIImage {
func symbolForNSToolbar() -> UIImage? {
guard let symbol = applyingSymbolConfiguration(.init(pointSize: 13)) else { return nil }
let format = UIGraphicsImageRendererFormat()
format.preferredRange = .standard
return UIGraphicsImageRenderer(size: symbol.size, format: format).image {
_ in symbol.draw(at: .zero)
}.withRenderingMode(.alwaysTemplate)
}
}
#endif
@malhal
Copy link

malhal commented Dec 19, 2019

Thanks "chevron.left" was too big for a back button until I found this

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