-
Notifications
You must be signed in to change notification settings - Fork 4
[iOS] Add documentation for using alternate app icons on iOS and tvOS. #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
344a6ca
Port Xamarin documentation about alternate app icons to .NET.
rolfbjarne 64595d0
port
rolfbjarne 18701c3
Fix according to review.
rolfbjarne 7322b1b
fix warnings
rolfbjarne 823d1c5
Try out xrefs
rolfbjarne ca1a5e2
create parent landing pages
rolfbjarne 84c9fee
More links
rolfbjarne 85a07fa
Fix yaml
rolfbjarne c78b38d
Fix yml format
rolfbjarne 4b53e07
Fix typo
rolfbjarne f17d02d
Apply suggestions from code review
rolfbjarne 5f298d5
Apply feedback.
rolfbjarne 9ee1d98
Fix warning.
rolfbjarne 0645b3d
Remove links to samples.
rolfbjarne 31977bc
Sentence case
rolfbjarne c3d3141
One more
rolfbjarne 0caf323
Revert "Remove links to samples."
rolfbjarne f251fe9
Link to location in repository
rolfbjarne 602472a
Merge remote-tracking branch 'origin/main' into alternate-app-icons
rolfbjarne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| - name: .NET for iOS, tvOS, macOS and Mac Catalyst | ||
| items: | ||
| - name: Application fundamentals | ||
| items: | ||
| - name: Images & icons | ||
| href: app-fundamentals/images-icons/index.md | ||
| items: | ||
| - name: Alternate app icons | ||
| href: app-fundamentals/images-icons/alternate-app-icons.md |
Binary file added
BIN
+48.8 KB
...ios/app-fundamentals/images-icons/alternate-app-icons-images/ScreenshotBlue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+48.9 KB
...os/app-fundamentals/images-icons/alternate-app-icons-images/ScreenshotGreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+148 KB
docs/ios/app-fundamentals/images-icons/alternate-app-icons-images/Step1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+273 KB
docs/ios/app-fundamentals/images-icons/alternate-app-icons-images/Step2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+212 KB
docs/ios/app-fundamentals/images-icons/alternate-app-icons-images/Step3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
129 changes: 129 additions & 0 deletions
129
docs/ios/app-fundamentals/images-icons/alternate-app-icons.md
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| --- | ||
| title: "Alternate app icons in .NET for iOS and tvOS" | ||
| description: "This document describes how to use alternate app icons. It discusses how to add these icons to a .NET for iOS or tvOS project, and how to manage the app's icon programmatically." | ||
| ms.date: 10/29/2024 | ||
| --- | ||
|
|
||
| # Alternate app icons in .NET for iOS and tvOS | ||
|
|
||
| Apple has several [UIApplication][uiapplication] APIs that allow an app to manage its icon: | ||
|
|
||
| - [UIApplication.SupportsAlternateIcons][supportsalternateicons] - If `true` the app has an alternate set of icons. | ||
| - [UIApplication.AlternateIconName][alternateiconname] - Returns the name of the alternate icon currently selected or `null` if using the primary icon. | ||
| - [UIApplication.SetAlternateIconName][setalternateiconname] - Use this method to switch the app's icon to the given alternate icon. | ||
| - `UNUserNotificationCenter.Current.SetBadgeCount` - Sets the badge count of the app icon in the Springboard (deprecated in iOS 16+ and tvOS 16+). | ||
|
|
||
|  | ||
|
|
||
| ## Adding alternate icons to a .NET project | ||
|
|
||
| To allow an app to switch to an alternate icon, a new `.appiconset` folder with a collection of icon images will need to be included in the project's asset catalog: | ||
|
|
||
| 1. Open the project's asset catalog (**Assets.xcassets**) in Finder: | ||
|
|
||
|  | ||
|
|
||
| 2. Create a copy of the existing `AppIcon.appiconset` folder: | ||
|
|
||
|  | ||
|
|
||
| 3. Replace each icon in the copied folder with the new icon of the matching size: | ||
|
|
||
|  | ||
|
|
||
| 4. Add the app icon to the project file using the `AppIcon` property: | ||
|
|
||
| ```xml | ||
| <PropertyGroup> | ||
| <AppIcon>AppIcon</AppIcon> | ||
| </PropertyGroup> | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| Existing projects typically specifies the app icon using the | ||
| `XSAppIconAssets` key in the `Info.plist` file - this can still be used, | ||
| but it's recommended to switch to the `AppIcon` property in the project | ||
| file instead (which is simplier too, because its value is the name of the | ||
| icon, not the path to the resource). | ||
|
|
||
| 5. Add the alternative icon(s) to the project file using the `AlternativeAppIcons` item group: | ||
|
|
||
| ```xml | ||
| <ItemGroup> | ||
| <AlternativeAppIcon Include="AlternativeAppIcons" /> | ||
| </ItemGroup> | ||
| ``` | ||
|
|
||
| ## Managing the app's icon | ||
|
|
||
| With the icon images included in the .NET project, the developer can the following ways to control the app's icon. | ||
|
|
||
| The [SupportsAlternateIcons][supportsalternateicons] property of the [UIApplication][uiapplication] class allows the developer to see if an app supports alternate icons. For example: | ||
|
|
||
| ```csharp | ||
| // Can the app select a different icon? | ||
| primaryIconButton.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons; | ||
| alternateIconButton.Enabled = UIApplication.SharedApplication.SupportsAlternateIcons; | ||
| ``` | ||
|
|
||
| The [ApplicationIconBadgeNumber][applicationiconbadgenumber] property of the [UIApplication][uiapplication] class allows the developer to get or set the current badge number of the app icon in the Springboard. The default value is zero (0). For example: | ||
|
|
||
| ```csharp | ||
| // Set the badge number to 1 | ||
| var badgeCount = 1; | ||
| UNUserNotificationCenter.Current.SetBadgeCount (badgeCount, (error) => { | ||
| Console.WriteLine ($"Set badge count to {badgeCount}: {(error is null ? "successfully" : error.ToString ())}"); | ||
| } | ||
| ``` | ||
|
|
||
| > [!NOTE] | ||
| `UNUserNotificationCenter.SetBadgeCount` requires authorization from the user on iOS, which can be acquired by calling `UNUserNotificationCenter.Current.RequestAuthorization` before setting the badge count. | ||
|
|
||
| The [AlternateIconName][alternateiconname] property of the [UIApplication][uiapplication] class allows the developer to get the name of the currently selected alternate app icon or it returns `null` if the app is using the Primary Icon. For example: | ||
|
|
||
| ```csharp | ||
| // Get the name of the currently selected alternate | ||
| // icon set | ||
| var name = UIApplication.SharedApplication.AlternateIconName; | ||
|
|
||
| if (name != null ) { | ||
| // Do something with the name | ||
| } | ||
| ``` | ||
|
|
||
| The [SetAlternameIconName][setalternateiconname] property of the [UIApplication][uiapplication] class allows the developer to change the app icon. Pass the name of the icon to select or `null` to return to the primary icon. For example: | ||
|
|
||
| ```csharp | ||
| void UsePrimaryIcon (Foundation.NSObject sender) | ||
| { | ||
| UIApplication.SharedApplication.SetAlternateIconName (null, (error) => { | ||
| Console.WriteLine ($"Set Primary Icon: {(error is null ? "successfully" : error.ToString ())}"); | ||
| }); | ||
| } | ||
|
|
||
| void UseAlternateIcon (Foundation.NSObject sender) | ||
| { | ||
| UIApplication.SharedApplication.SetAlternateIconName ("AlternateAppIcons", (error) => { | ||
| Console.WriteLine ($"Set Alternate Icon: {(error is null ? "successfully" : error.ToString ())}"); | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| When the app is run and the user selects an alternate icon, an alert like the following will be displayed: | ||
|
|
||
|  | ||
|
davidbritch marked this conversation as resolved.
Outdated
|
||
|
|
||
| If the user switches back to the primary icon, an alert like the following will be displayed: | ||
|
|
||
|  | ||
|
davidbritch marked this conversation as resolved.
Outdated
|
||
|
|
||
| ## See also | ||
|
|
||
| - [iOS sample](https://github.com/dotnet/macios-samples/tree/main/AlternateAppIcons/iOS) | ||
| - [tvOS sample](https://github.com/dotnet/macios-samples/tree/main/AlternateAppIcons/tvOS) | ||
|
|
||
| [uiapplication]: xref:UIKit.UIApplication | ||
| [applicationiconbadgenumber]: xref:UIKit.UIApplication.ApplicationIconBadgeNumber | ||
| [supportsalternateicons]: xref:UIKit.UIApplication.SupportsAlternateIcons | ||
| [alternateiconname]: xref:UIKit.UIApplication.AlternateIconName | ||
| [setalternateiconname]: xref:UIKit.UIApplication.SetAlternateIconName%2A | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| title: "Images and Icons in .NET for iOS, tvOS, macOS and Mac Catalyst" | ||
| description: "This section includes a variety of articles that cover working with images in a Xamarin.iOS app, such as using them as icons, launch screens or including them in controls and providing icons for custom document types." | ||
| ms.date: 11/01/2024 | ||
| --- | ||
| # Images and icons in .NET for iOS, tvOS, macOS and Mac Catalyst | ||
|
|
||
| There are several ways that image assets are used inside an app. From simply | ||
| displaying an image as part of an app's UI to, assigning it to a UI control | ||
| such as a [UIButton][uibutton] or [UIImageView][uiimageview], to providing icons and launch | ||
| screens, .NET for iOS, tvOS, macOS and Mac Catalyst makes it easy to add great | ||
| artwork to an app in the following ways: | ||
|
|
||
| - **Resolution Independent Images** – Use the OS's built-in support for working with images across different device resolutions and types (iPhone, iPad, etc.). | ||
| - **Asset Catalog Image Sets** - Use **Asset Catalog Image Sets** to manage and group all version of a given image asset required by an app. | ||
| - **Images in Code** – Use the [UIImage][uiimage] class's methods to load and work with image assets and assign them to UI controls in C# code. | ||
| - **Application Icon** - Define the app icon required by every app. This is the icon that the user will tap from the home screen to launch the app. Additionally, this icon is used by Game Center, if applicable. | ||
| - **Spotlight Icon** - Define the app's Spotlight icon. Whenever the user enters the name of an app in a Spotlight Search, this icon is displayed. | ||
| - **Settings Icon** - Define the app's **Settings** icon. If the user enters the **Settings** app on their device, this icon will be displayed at the end of the Settings list for the app. | ||
| - **Launch Screens** - Define the app's Launch Screen. After the user taps the app icon and before the first view appears, a blank screen will be shown. Fortunately, it's possible to displaying an image in place of the blank screen by using a Storyboard. | ||
| - **iTunes Icon** - Provide an iTunes icon. If using the Ad-Hoc method of delivering an app (either for corporate users or for beta testing on real devices), the developer also needs to include a 512x512 and a 1024x1024 image that will be used to represent the app in iTunes. | ||
| - **Document Icons** - Use an image as an icon for any specific document type that an app supports or creates. | ||
|
|
||
| There are several considerations that should be taken into account when | ||
| creating image assets for an app, as well as several places where those assets | ||
| will be used. Each of these have an affect on not only how many image assets | ||
| will be required, but how those assets are created. The following topics cover | ||
| the types of images assets that will be required, how those assets are | ||
| included in the application's bundle and how the image assets are consumed to | ||
| provide the required functionality: | ||
|
|
||
| ## [Alternate app icons](~/ios/app-fundamentals/images-icons/alternate-app-icons.md) | ||
|
|
||
| Apple has several [UIApplication][uiapplication] APIs that allow an app to manage its icon: | ||
|
|
||
| - [UIApplication.SupportsAlternateIcons][supportsalternateicons] - If `true` the app has an alternate set of icons. | ||
| - [UIApplication.AlternateIconName][alternateiconname] - Returns the name of the alternate icon currently selected or `null` if using the primary icon. | ||
| - [UIApplication.SetAlternateIconName][setalternateiconname] - Use this method to switch the app's icon to the given alternate icon. | ||
| - `UNUserNotificationCenter.Current.SetBadgeCount` - Sets the badge count of the app icon in the Springboard (deprecated in iOS 16+ and tvOS 16+). | ||
|
|
||
| [uiapplication]: xref:UIKit.UIApplication | ||
| [applicationiconbadgenumber]: xref:UIKit.UIApplication.ApplicationIconBadgeNumber | ||
| [supportsalternateicons]: xref:UIKit.UIApplication.SupportsAlternateIcons | ||
| [alternateiconname]: xref:UIKit.UIApplication.AlternateIconName | ||
| [setalternateiconname]: xref:UIKit.UIApplication.SetAlternateIconName%2A | ||
| [uibutton]: xref:UIKit.UIButton | ||
| [uiimageview]: xref:UIKit.UIImageView | ||
| [uiimage]: xref:UIKit.UIImage |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| ### YamlMime:Hub | ||
|
|
||
| #root section (Required) | ||
| title: .NET for iOS, tvOS, macOS and Mac Catalyst documentation | ||
| summary: > | ||
| .NET for iOS, tvOS, macOS and Mac Catalyst allows you to write apps for iOS, tvOS, macOS or Mac Catalyst using .NET languages. | ||
| brand: dotnet | ||
|
|
||
| metadata: | ||
| title: .NET for iOS, tvOS, macOS and Mac Catalyst | ||
| description: The .NET for iOS, tvOS, macOS and Mac Catalyst guide has everything you need to learn .NET for these platform. | ||
| ms.subservice: dotnet-ios | ||
| ms.topic: hub-page | ||
| author: rolfbjarne | ||
| ms.author: rokvin | ||
| ms.date: 11/01/2024 | ||
|
|
||
| conceptualContent: | ||
| # itemType: reference | ||
| # Supports up to 3 subsections | ||
| sections: | ||
| - title: .NET for iOS, tvOS, macOS and Mac Catalyst Guides | ||
| items: | ||
| # Card | ||
| - title: Application fundamentals | ||
| links: | ||
| - url: ~/ios/app-fundamentals/images-icons/alternate-app-icons.md | ||
| itemType: reference | ||
| text: Alternate app icons | ||
|
|
||
| # additionalContent section (Optional; Remove if not applicable.) | ||
| # Card with links style | ||
| additionalContent: | ||
| # Supports up to 4 subsections | ||
| sections: | ||
|
|
||
| - title: References # < 60 chars (optional) | ||
| items: | ||
| # Card | ||
| - title: ".NET API reference" | ||
| summary: API reference documentation for .NET | ||
| url: /dotnet/api/?view=net-9.0 | ||
|
|
||
| # footer (Optional; Remove if not applicable.) | ||
| footer: "Are you interested in contributing to the .NET docs? For more information, see our [contributor guide](/contribute/dotnet/dotnet-contribute)." |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Image needs resizing - look at the preview at https://review.learn.microsoft.com/en-us/dotnet/ios/app-fundamentals/images-icons/alternate-app-icons?branch=pr-en-us-53