• Stars
    star
    670
  • Rank 67,354 (Top 2 %)
  • Language
    Swift
  • Created almost 11 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

📐 Guide to name iOS assets

Guide for Naming Assets in iOS Projects

This guide outlines best practices and naming conventions to help graphic designers and developers manage a large number of icons prepared for an iOS project.

Your input is welcome: pull requests or Twitter 😄

Table Of Contents

Namespace

Naming an asset starts with breaking up the user interface of each screen into namespaces (or sections). Each namespace represents a logical grouping for the assets and can be used to create asset names.

  • Shorter is better (one word if possible).
  • Meaningful namespace name.
  • Use lower case.
  • No spaces or special characters (use dashes).

Namespaces can correspond to view controllers, typical namespaces are top, bottom, content although more specific names are better.

Examples

Twitter Profile Tumblr Home Instagram Explore
top
actions
tweet
tab
post
tab
top
photo
tab

Asset Folder

  • Using Asset Catalogs is the preferred way to manage assets in Xcode, it eliminates keeping track of files in a project. However naming assets (image sets) remains important especially when collaborating with a designer.
  • If you choose to manage assets directly, use a main folder to store all assets for the app (usually named assets or images). This may seem radical but it works in conjunction with prefixing.

Asset Types

PNG

PNG is typically used for icons (JPG is better for photos).

  • PNG is good for small assets.
  • PNG is non-lossy.
  • PNG supports transparency.

To use PNG assets:

  1. Create 1x, 2x and 3x assets in the same folder.
  2. Add @2x or @3x at the end of the appropriate asset name.

To save disk space or time, one can omit the 1x, 2x or 3x asset: the system automatically scales up or down for the appropriate resolution (in particular, you could provide only 2x/3x assets when targeting retina devices).

PDF

Xcode 6 added support for PDF / vector icons eliminating the need for multiple resolution per asset (goodbye 1x, 2x, 3x). However doing so will

re-create PNG assets at compile time, embedding the rasterized bitmaps in the final application instead of embedding the original PDF vector image.

If you add PDF files directly as resources, they can be used as vector assets which have no size restriction (like an icon font).

If you still want to use a PDF asset with assets catalogs, create an image set for each PDF asset in Xcode. Then in the Utility panel (right) set:

  • Devices: Universal
  • Scale Factors: Single Vector
  • Render As: Template Image (corresponds to setting the UIImageRenderingMode property to UIImageRenderingModeAlwaysTemplate)

This last setting allows an asset to be tinted (colored). If setting up a large number of assets sounds tedious, check out a tool appropriately called pdf_xcassets.

PDF assets still need to be sized appropriately, i.e. the designer would provide 2 assets for an arrow if the mockup required assets sized 20x20 and 40x40. For more details, read this article.

Icon Font

Another alternative for icon generation is to use icon fonts. These can be scaled without quality loss and colored just like any text. For more details, read this article.

Tools

Here are some tools to help you manage your assets.

  • blade: Generate Xcode image catalogs for iOS / OSX app icons, universal images, and more.
  • Cat2Cat: Generate a category on UIImage from asset catalogs in order to reduce typos and enable Xcode auto-completion.
  • OHPDFImage: A library to easily load PDF files as UIImages.
  • pdf_xcassets: Generate Xcode xcassets for pdf assets.
  • Synx: A command-line tool that reorganizes your Xcode project folder to match your Xcode groups.

Swift Enums

  • Misen: Script to support using Xcode Asset Catalog in Swift.
  • SwiftGen: A collection of Swift tools to generate Swift code (enums for your assets and more).

Naming

Uniqueness

An important attribute of an asset name is uniqueness.

  • This prevents confusion: for example having two different share assets (say one for iPhone and one for iPad, or one in a main view and one in a detail view).
  • More importantly, while it is possible in Xcode to have two files of the same names in different folders, you can only reference one of them using + (UIImage *)imageNamed:(NSString *)name.
  • Update: Asset catalogs support a namespace based on the asset "Group" that allows for the same name to be reused (read the documentation or summary).
"properties" : {
      "provides-namespace" : true
}

Prefixing

Prefixing is optional but it ensures that asset names are unique across the project.

  • Prefix the asset with the app name so you can tell which project it belongs to (use a 2 or 3 letter prefix for long app names).
  • Add a device prefix (especially for universal apps with device-specific assets).
  • Add a namespace prefix so you can quickly organize your assets.
  • Format: project-device-namespace-asset-name.png
ss-ipad-intro-arrow-right.png
bpc-iphone-intro-arrow-right.png

twitter-iphone-top-user.png
twitter-iphone-top-search.png
twitter-iphone-top-write.png

tumblr-iphone-card-action.png
tumblr-iphone-card-comment.png
tumblr-iphone-card-reblog.png
tumblr-iphone-card-heart.png

Conventions

  • The asset name describes the icon, not the function of the icon (when possible, see special cases).
  • Use lower case.
  • No spaces or special characters (use dashes).

Examples

ss-rack-minus.png
ss-top-bars.png
ss-tree-check.png

Not

delete.png
menu.png
selected.png

While CamelCase is the convention in Objective-C, it does not necessarily mean it needs to be applied to asset names (by all means feel free to use it if you prefer SSRackMinus.png).

Notable

  • chevron for >
  • caret for

Special cases

Sometimes the name is well represented by its function (refer to Charbase for Unicode).

  • refresh for open circle arrow (⟳ U+21BB)
  • edit for pencil (✎ U+270E)
  • search for magnifying glass (🔍 U+1F50D)
  • user for bust in silhouette (👤 U+1F464)
  • comment for speech balloon (💬 U+1F4AC)

Collisions

Should two assets have the same name, add a qualifier at the end.

Color qualifer
ss-top-plus-pink.png
ss-top-plus-gray.png
Shape qualifer
  • *-square
  • *-circle
  • *-outline
ss-top-arrow-right-circle.png
ss-top-arrow-right-square.png
Combine shapes
  • *-square-outline for square and outline
Direction qualifer
  • *-right
  • *-left
  • *-up, etc
ss-top-arrow-right.png
ss-top-arrow-square-right.png
Buttons (control states)
  • *-normal
  • *-selected
  • *-highlighted, etc
ss-profile-gear-normal.png
ss-profile-gear-highlighted.png
Orientation
  • *-portrait
  • *-landscape
  • *-landscape-right, etc

Apple recommends using Xcode storyboards for launch screens.

Spelling

In the US, we would favor American over British spelling (sorry M'lady).

Examples

ss-top-hanger-gray.png  
ss-tree-color-swatch.png

Not

hanger-grey.png  
colour-swatch.png

Abbreviations

Do not abbreviate.

Examples

ss-share-facebook.png
ss-share-twitter.png  

Not

fb.png
tw.png

Acknowledgment

This guide was inspired by the NYTimes Objective-C Style Guide and Font Awesome.

Special thanks to the following individuals for their feedback: Ash Furrow, Sergio Campama, Matteo Crippa, Marco Sousa, Dave McKinney.

Contact

More Repositories

1

open-source-ios-apps

📱 Collaborative List of Open-Source iOS Apps
41,887
star
2

awesome_bot

✅ Validate links in awesome projects
Ruby
826
star
3

frankenstein

:octocat: Correct README Redirects
Ruby
308
star
4

ScrollTab

Scrolling Tab for iOS
Objective-C
267
star
5

dkhamsing.github.io

:octocat: My GitHub Page
Ruby
221
star
6

news

📰 iOS news app in the style of Apple News, CNN, BBC, Facebook, NYT, Twitter, Reddit & more
Swift
217
star
7

TabDump

📰 TabDump app for iOS
Objective-C
98
star
8

osia

:octocat: iOS app to browse open-source-ios-apps
Swift
88
star
9

apns-guide

🔔 Guide to setup APNS
86
star
10

DKImageBrowser

iOS Image Browser with a Thumbnail Strip
Objective-C
56
star
11

stocks

📈 Basic iOS app to track stocks (data from Finnhub, Tiingo, or IEX Cloud)
Swift
42
star
12

covid19.swift

🌐 Small iOS app to show some COVID-19 health, data, news and tweets
Swift
27
star
13

listapp.ios

✨ Basic lists from iOS 2 to iOS 15
Swift
27
star
14

fastmdb

🔍 Fast iOS app to browse and search movies, tv, actors, credits
Swift
22
star
15

how-much

💰 iOS price list app using Firebase, Realm & more
Objective-C
21
star
16

xcode-readme

🔍 Correct the spelling of Xcode in a README
Ruby
10
star
17

GitHubOAuthController

:octocat: Simple GitHub OAuth Controller for iOS
Objective-C
10
star
18

cocoapods-readme

🔍 Correct the spelling of CocoaPods in a README
Ruby
9
star
19

pdf_xcassets

🚋 Generate Xcode xcassets for PDF assets
Ruby
8
star
20

upcomingtv

📆 iOS app to track when your favorite tv show airs next
Swift
8
star
21

github-readme

:octocat: Get the README from a GitHub repo
Ruby
6
star
22

update_profile_pic

👤 Update your Twitter profile pic in a snap
Ruby
6
star
23

delete_my_tweets

🐤 Delete my tweets
Ruby
5
star
24

markdown_html

📄 The simplest way to convert Markdown to HTML
Ruby
4
star
25

readme-correct

😁 Fix GitHub typos with ease
Ruby
4
star
26

tumblr_uploadr

🐼 Tumblr photo batch uploader
Ruby
3
star
27

forker

🍴 Fork GitHub repos found on a page
Ruby
2
star
28

covid19cli

⚡ Quick CLI for COVID-19 data
Ruby
2
star
29

twitter_oauth_token

✋ Twitter OAuth token Ruby library
Ruby
1
star