IconSelector

1.0.0

A drop-in UI component to allow easy selection of alternate icons on iOS.
jellybeansoup/ios-icon-selector

What's New

v1.0.0

2021-01-22T01:02:42Z
  • Initial release
  • Includes SPM, Carthage, and CocoaPods support

IconSelector

IconSelector

A drop-in UI component to allow easy selection of alternate icons on iOS.

Why?

Adding alternative icons to an iOS app isn't entirely straightforward, but it should be. It's tricky enough to add the entries to your Info.plist, let alone implement UI that you can display on both iPhone and iPad. This library takes care of that last part, and leaves you the much easier task of choosing the icons you want to add!

Features

  • Build on top of UIControl.
  • Adjustable borders, padding, labels, etc.
  • Drop in as-is, or use it to power custom UI.
  • Compatible with iOS 10.3 and above.

IconSelector in Slopes IconSelector in GIFwrapped

Installation

Swift Package Manager (for Apple platforms only)

In Xcode, select File > Swift Packages > Add Package Dependency and enter the repository URL:

https://github.com/jellybeansoup/ios-icon-selector

Add the following line to your Cartfile:

github "jellybeansoup/ios-icon-selector"

Getting Started

Begin by defining your alternate icons under the CFBundleIcons key within your app's Info.plist file. Don't forget to include an entry for your app's primary icon!

<key>CFBundleIcons</key>
<dict>
	<key>CFBundleAlternateIcons</key>
	<dict>
		<key>blue</key>
		<dict>
			<key>CFBundleIconFiles</key>
			<array>
				<string>blue-20</string>
				<!-- Include all the relevant sizes! -->
			</array>
		</dict>
	</dict>
	<key>CFBundlePrimaryIcon</key>
	<dict>
		<key>CFBundleIconFiles</key>
		<array>
			<string>green-83.5</string>
			<!-- Include all the relevant sizes! -->
		</array>
	</dict>
</dict>

Next, instantiate the IconSelector and add it to your view heirarchy. The IconSelector class inherits from UIControl, so you'll also need to add a target/action pair to be notified when the user selects a different icon.

// Goes at the top of the file.
import IconSelector

// Retrieve all the icons defined in your app's main bundle.
let icons = Icon.main

// Instantiate the IconSelector with a target/action combo, and add it to your view hierarchy.
let iconSelector = IconSelector(icons: icons)
iconSelector.addTarget(self, action: #selector(iconSelectorDidChange(_:)), for: .valueChanged)
view.addSubview(iconSelector)

Finally, implement the action needed to change the app's icon in response to the user's selection.

@objc func iconSelectorDidChange(_ iconSelector: IconSelector) {
	guard UIApplication.shared.supportsAlternateIcons, let selectedIcon = iconSelector.selectedIcon else {
		return
	}

	UIApplication.shared.setAlternateIcon(selectedIcon, completionHandler: nil)
}

Documentation

You can find complete documentation for this project here. This documentation is automatically generated with jazzy from a GitHub Action and hosted with GitHub Pages.

To generate documentation locally, run make documentation or sh ./scripts/documentation.sh from the repository's root directory. The output will be generated in the docs folder, and should not be included with commits (as the online documentation is automatically generated and updated).

Released under the BSD License

Copyright © 2021 Daniel Farrelly & Curtis Herbert

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Nov 10 2024 20:20:56 GMT-1000 (Hawaii-Aleutian Standard Time)