Created
October 22, 2019 03:07
-
-
Save JunyuKuang/b3da6c487d5248293e876c1e47984776 to your computer and use it in GitHub Desktop.
[Mac Catalyst] a helper method that creates NSToolbar image with SF Symbol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIImage+NSToolbar.swift | |
// MobileReaderUI | |
// | |
// Created by Jonny Kuang on 10/12/19. | |
// Copyright © 2019 Junyu Kuang <[email protected]>. 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks "chevron.left" was too big for a back button until I found this