Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Defining and Using the kTransformFocused IconTransformType
Q: How can I draw a selected icon with a focus ring like the HIToolbox does in a HIToolbar?
A: How can I draw a selected icon with a focus ring like the HIToolbox does in a HIToolbar?
There is a special IconTransformType value which can be used with PlotIconRefInContext, and only PlotIconRefInContext, in order to get the desired result. This IconTransformType is available in Mac OS X since version 10.3 but is not exported in the headers.
It will be documented in Icons.h in a later release of the Development Tools but you can start using it right now by defining it yourself:
Listing 1 Defining the kTransformFocused IconTransformType.
enum { kTransformFocused = 0x8000 }; |
Then you just use this IconTransformType like any other as in the sample code extract below:
Listing 2 Using the kTransformFocused IconTransformType.
IconRef iconRef; status = GetIconRef(kOnSystemDisk, kSystemIconsCreator, kGenericApplicationIcon, &iconRef); require_noerr(status, bail); status = PlotIconRefInContext( context, &iconRect, kAlignNone, kTransformNone, &color, kPlotIconRefNormalFlags, iconRef); require_noerr(status, bail); iconRect = CGRectOffset(iconRect, 160, 0); status = PlotIconRefInContext( context, &iconRect, kAlignNone, kTransformFocused, &color, kPlotIconRefNormalFlags, iconRef); require_noerr(status, bail); |
And this code should draw the following icons:

However, if the icon is clipped, for example by its parent view (see Figure 2 and Figure 3), then the focus ring will be partly drawn outside the clip area, leaving an undesired graphic artifact (in this example, at the bottom of the icon). This is a purely cosmetic bug and is a known problem.


Document Revision History
Date | Notes |
---|---|
2005-03-29 | New document that documents a new IconTransformType, available in Panther and later, which draws a focus ring around an icon. |
Copyright © 2005 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2005-03-29