ControlWidgetToggle image design

I need help designing the image of a ControlWidgetToggle.

  1. do I understand correctly that I can only use an SFSymbol as image and not my custom image (unless setup via a custom SFSymbol)?
  2. is there any way I can influence the size of the image? I tried multiple SwiftUI modifiers (.imageScale, .font, .resizable, .controlSize) none of them seem to work. My image remains too tiny
  3. the image size of the on and off state is different. Seems to be enforced by the system. Is there any way to make both images use the same size?
  4. the on-state tints the image. Is there a way to set the tint color? .tint and .foregroundstyle seem to be ignored.

Thank you for your help

Thanks for the question. When creating an image I now like to use the same size for all of them to avoid issues and work on trying to size everything correctly.

I am a big fan of this tool https://developer.apple.com/icon-composer/ I would recommend you to start using it for your needs and generate the correct sizes for the correct platform.

Use custom images by creating a custom view. Here’s an example to set up a custom toggle with a custom image. The modifier sets the image size, ensuring it maintains its aspect ratio while fitting within the frame. Since uses system symbols by default, the size difference between the on and off states is inherent. Use the same image for both states by not changing the symbol when toggling.

SF Symbols are vector-based, rendering clearly at various sizes. They align with text and support different weights and scales (small, medium, large). The point size is expressed as a font point size, not a screen dimension. The system adjusts the stroke thickness to match the text weight and centers symbols vertically to the cap height.

To customize the appearance of a ControlWidgetToggle, use a Label with both text and a system image. The system handles the scaling and appearance of SF Symbols based on the context. If a fixed size is necessary, set the symbol’s point size. For custom fonts, use SymbolConfiguration(font:) to create a configuration that matches the font, ensuring a high-fidelity appearance.

The imageScale, font, resizable, and controlSize modifiers might not produce the expected results for ControlWidgetToggle images because the system manages the scaling and presentation of control visuals. The system prioritizes contextual display, which can override direct size manipulations. Focus on providing appropriate SF Symbols and leveraging the system’s automatic scaling and alignment capabilities.

Introducing SF Symbols https://developer.apple.com/videos/play/wwdc2019/206

Resource for control widget https://developer.apple.com/documentation/widgetkit/controlwidgettoggle

Hope this helps,

Albert Pascual
  Worldwide Developer Relations.

ControlWidgetToggle image design
 
 
Q