UIBarButtonItem
Image Size
iOS Development
User Interface Design
Apple Guidelines

How big should a UIBarButtonItem image be?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Overview

When developing iOS applications, providing a visually consistent and user-friendly interface is crucial. Among the various UI components, `UIBarButtonItem` is commonly used in navigation and toolbar components. A common question for developers is: "How big should the image be for a `UIBarButtonItem`?". This article aims to address this question with technical details, including resolutions, rendering modes, and best practices.

Image Dimensions and Resolutions

Standard Sizes

Apple recommends specific image sizes for different `UIBarButtonItem` types:

  • Toolbar Icons:
    • Standard: 22x22 points (44x44 pixels for @2x and 66x66 pixels for @3x)
  • Navigation Bar Icons:
    • Standard: 24x24 points (48x48 pixels for @2x and 72x72 pixels for @3x)

The dimensions above are given in points, which is a resolution-independent measurement. iOS automatically scales these based on the device's pixel density.

Understanding Point vs. Pixel

Points are a more precise way of defining sizes in iOS, as they automatically adapt to different screen densities. Here's how it breaks down:

  • @1x: 1 point = 1 pixel
  • @2x: 1 point = 2x2 pixels or 4 pixels
  • @3x: 1 point = 3x3 pixels or 9 pixels

Using the correct size ensures that your images display sharply without distortion on devices with different screen resolutions.

Rendering Modes

Template vs. Original

`UIBarButtonItem` typically uses the `UIImage` class to handle image rendering modes. There are two main rendering modes:

  • UIImageRenderingModeAlwaysTemplate:
    • The image is rendered as a template image, meaning its color is ignored, and it inherits the tint color of the `UIBarButtonItem`.
  • UIImageRenderingModeAlwaysOriginal:
    • The image is drawn with its original colors, without any color modification.

Using a template rendering mode is generally recommended for button images, aligning with the app's theme and ensuring consistent appearance across different UI elements.

Implementation Example

Here's a Swift snippet demonstrating how to create a `UIBarButtonItem` with a custom image:

  • Avoid Over-detailed Icons: Given the small size of `UIBarButtonItem` images, maintaining simplicity is key. Complex details may not be clear at smaller sizes.
  • Use Vector Graphics: Whenever possible, use vector graphics (such as PDF format) to easily adapt to different sizes and resolutions.
  • Maintain Equal Margins: Ensure that your images are visually centered, maintaining equal spacing from the button edges.
  • Test Across Devices: Ensure your images appear accurately across different devices, especially with varying screen sizes and pixel densities.

Course illustration
Course illustration

All Rights Reserved.