Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.
preface
Earlier I introduced the classification of dark mode adaptation and UIColor. Today I’m going to continue with UI. It’s a library called SFSafeSymbols.
SF Symbols
Before we talk about this library, let’s talk about an Apple software called SF Symbols.
Here the software is used for what, I last screenshot you know:
SF Symbols was launched during WWDC 2019. Since then, Apple has provided free Symbols for us to use in our apps, and it’s very easy to use them.
To put it simply, Apple officially provides a set of UI materials for developers to use.
After WWDC 2020 and WWDC 2021, SF Symbols has reached 3.0.
So how do we use it?
For example, I think the first icon in the above picture is good, and I want to develop it in iOS, I will right click and copy the name:
Then call it through the function:
let image = UIImage(systemName: "folder.badge.person.crop")
Copy the code
Let’s look at the systemName initialization function as a whole:
Open class UIImage: NSObject, NSSecureCoding {@available(iOS 13.0, *) public /*not inherited*/ init? (systemName name: String) }Copy the code
It’s available after iOS13, optional constructor, and it returns UIImage, okay? Type, the name passed in is a string, hard coded, unsafe.
That’s when the SFSafeSymbols should hit the scene.
SFSafeSymbols
A SF Symbol UIImage can now be initialized using the SFSymbol enum. This image is already unwrapped, so you get a UIImage instead of a UIImage? :
UIImage(systemSymbol: .cCircle)
UIImage(systemSymbol: SFSymbol.eCircleFill)
UIImage(systemSymbol: ._11CircleFill, withConfiguration: /* Some UIImage.Configuration */)
Copy the code
With SFSafeSymbols, you can initialize an unwrapped image using the enum in the SFSymbol provided by the library, and return UIImage, not UIImage? To solve the hard coding problem.
More detailed usage, you can go to Github to check, I don’t need to write more ink.
Now, with SFSafeSymbols, I don’t have to worry about UI.
Reference Documents:
SF Symbols
SFSafeSymbols
Introduction of SF, Symbols
conclusion
With the query of SF Symbols software and secure call of SFSafeSymbols, we can call the ICONS designed by Apple well.
This is a good thing for indie developers, or those who are struggling to find material.
We can even share SF Symbols with the UI to get them to design more Apple ICONS.
Of course, since SF Symbols only supports iOS 13, this is a real pain point.
We’ll see you next time.