Skip to content

Commit d907d83

Browse files
authored
Update README
1 parent 95bad8c commit d907d83

File tree

1 file changed

+53
-11
lines changed

1 file changed

+53
-11
lines changed

README.md

+53-11
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ NSIcon provides a easy-to-use Mac app icon view for SwiftUI programming, reducin
1414
## Overview
1515

1616
### NSIcon
17+
#### Available: macOS
18+
1719
Using `NSIcon` is as simple as the built-in `Image` view in SwiftUI.
1820
You can get access to almost any app icon installed on your Mac.
1921

2022
```swift
21-
// Use the parameterless initializer if you want to access the icon of your app itself.
23+
// Use `init()` if you want to access the icon of your app itself.
2224
NSIcon()
2325

2426
// Get an app icon view by name.
@@ -30,40 +32,64 @@ NSIcon(bundleIdentifier: "com.apple.safari")
3032

3133
If the corresponding icon cannot be provided, NSIcon displays the GenericApplicationIcon that comes with macOS by default.
3234

33-
<p align="center">
34-
<img src="https://github.com/Stv-X/NSIcon/assets/30586070/de3a0c5c-8517-4887-9d65-04335d53c812"
35-
alt="GenericApplicationIcon" width="128"/>
36-
</p>
37-
3835
You can use `iconPlaceholderStyle` modifier to get a different appearance of the placeholder.
3936

4037
```swift
4138
NSIcon("unknown")
4239
.iconPlaceholderStyle(.classic)
4340
```
4441

45-
<p align="center">
46-
<img src="https://github.com/Stv-X/NSIcon/assets/30586070/56374d34-cd6b-48fc-9b1f-c005be6dea3d"
47-
alt="GenericApplicationIconClassic" width="128"/>
48-
</p>
42+
![GenericAppIconStyles](https://github.com/Stv-X/NSIcon/assets/30586070/3a151568-b0b5-433b-9662-d3dca5f26290)
43+
44+
45+
### UIIcon
46+
#### Available: iOS, iPadOS, Mac Catalyst, watchOS, visionOS
47+
48+
Considering the app sandbox environment on these platforms, the icon file assets of other apps are inaccessible, `UIIcon` only provides the ability to access icon of the app itself.
49+
50+
Unlike the behavior of `NSIcon`, `UIIcon` adds mask to the icon by default. Use parameter `addMask: Bool` to control.
51+
52+
On different platforms, the appearance of masks are different.
53+
54+
| Platform | iOS | iPadOS | Mac Catalyst | watchOS | visionOS |
55+
| :------: | :----------------------------------------------------------: | ------------------------------------------------------------ | :----------------------------------------------------------: | :-----: | :------: |
56+
| Mask | [AppIconMask](https://github.com/Stv-X/NSIcon/tree/main/Sources/NSIcon/Media.xcassets/AppIconMask.imageset) | [AppIconMask](https://github.com/Stv-X/NSIcon/tree/main/Sources/NSIcon/Media.xcassets/AppIconMask.imageset) | [MacAppIconMask](https://github.com/Stv-X/NSIcon/tree/main/Sources/NSIcon/Media.xcassets/MacAppIconMask.imageset) | Circle | Circle |
57+
58+
```swift
59+
UIIcon()
60+
UIIcon(addMask: false)
61+
```
62+
63+
In visionOS, the app icon consists of three different layers. Use `init()` to render a merged version by default.
64+
You can also use `init(_ layer: AppIconlayer)` or `init(_ layers: [AppIconlayer])` to select which parts of the icon to display.
4965

66+
```swift
67+
UIIcon(.back)
68+
UIIcon([.middle, .front])
69+
```
70+
71+
> Note: `UIIcon` does not support `iconPlaceholderStyle` modifier.
5072
5173
### NSAsyncIcon
74+
#### Available: macOS
75+
5276
`NSAsyncIcon` behaves similarly to `NSIcon`, it obtains app icon from the App Store by accessing [iTunes Search API](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI).
5377

5478
```swift
5579
NSAsyncIcon("Pages")
5680
NSAsyncIcon(bundleIdentifier: "com.apple.iwork.pages")
5781
```
5882

59-
When using `appName` as an initialization parameter, you can set your preferences for iOS app or macOS app to decide the results you receive. The default is `.macOS`.
83+
When using `appName` as an initialization parameter, you can set your preferences for iOS, macOS, watchOS or visionOS app to decide the results you receive. The default is `.macOS`.
6084

6185
```swift
6286
NSAsyncIcon("Pages", for: .iOS)
6387
```
6488

6589
iOS app icons and a few of macOS app icons present in a opaque square shape. Therefore, consider whether to add a rounded rectangle mask to it. The default is `false`.
6690

91+
> Note: `NSAsyncIcon` will check if this icon contains transparent pixels. If so, the mask will not be added to the view.
92+
6793
```swift
6894
NSAsyncIcon("Pages", for: .iOS, addMask: true)
6995
```
@@ -80,6 +106,22 @@ NSAsyncIcon("原神", country: "CN")
80106

81107
![NSAsyncIconCountryPreview](https://github.com/Stv-X/NSIcon/assets/30586070/b88c6e18-8907-4be5-b855-0584c1d8eaf2)
82108

109+
### UIAsyncIcon
110+
#### Available: iOS, iPadOS, Mac Catalyst, watchOS, visionOS
111+
112+
`UIAsyncIcon` works almost exactly the same as `NSAsyncIcon`, check the differences below:
113+
1. Add a mask to the icon by default
114+
2. `for platform: AppPlatform` parameter defaults to `.iOS`
115+
3. Support custom placeholder
116+
4. The `placeholderStyle` modifier is not supported
117+
118+
`UIAsyncIcon` uses a `ProgressView()` as the default placeholder, to create a custom placeholder, just add a custom view to the `placeholder` closure.
119+
120+
```swift
121+
UIAsyncIcon("Pages") { CustomPlaceholder() }
122+
```
123+
124+
83125
## Installation
84126

85127
NSIcon is available with Swift Package Manager.

0 commit comments

Comments
 (0)