<!--
{
  "availability" : [
    "iOS: 8.0.0 - 9.0.0",
    "iPadOS: 8.0.0 - 9.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIAppearance/appearanceForTraitCollection:whenContainedIn:",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UIAppearance(cm)appearanceForTraitCollection:whenContainedIn:"
  },
  "title" : "appearanceForTraitCollection:whenContainedIn:"
}
-->

# appearanceForTraitCollection:whenContainedIn:

Returns the appearance proxy for the object when it’s contained in the hierarchy the specified classes describe and has the specified trait collection.

```
+ (instancetype) appearanceForTraitCollection:(UITraitCollection *) trait whenContainedIn:(Class<UIAppearanceContainer> *) ContainerClass;
```

## Parameters

`trait`

The trait collection to use for matching.

`ContainerClass`

A nil-terminated list of appearance container classes, in ascending hierarchical order.

## Return Value

The appearance proxy to use for the object.

## Discussion

Set the `ContainerClass` array to an ascending hierarchical list of types where the appearance settings should apply when the caller type is contained within them for the trait collection. For example, if you want a `UINavigationBar` to take on a specific appearance when contained in a `UINavigationController` inside a `UITabBarController`, set `ContainerClass` to `@[[UINavigationController class], [UITabBarController class], nil]`.

Do not set `ContainerClass` to an unrelated list of types or to a list that does not match the containment hierarchy of your user interface.

This method throws an exception for any item in the var-args list that is not a Class object that conforms to the `UIAppearanceContainer` protocol.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)