pub struct UITraitCollection { /* private fields */ }UITraitCollection only.Expand description
A trait collection encapsulates the system traits of an interface’s environment.
See also Apple’s documentation
Implementations§
Source§impl UITraitCollection
impl UITraitCollection
pub fn init(this: Allocated<Self>) -> Retained<Self>
Sourcepub unsafe fn initWithCoder(
this: Allocated<Self>,
coder: &NSCoder,
) -> Option<Retained<Self>>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
§Safety
coder possibly has further requirements.
pub fn containsTraitsInCollection( &self, trait: Option<&UITraitCollection>, ) -> bool
pub fn traitCollectionWithTraitsFromCollections( trait_collections: &NSArray<UITraitCollection>, ) -> Retained<UITraitCollection>
pub fn traitCollectionWithUserInterfaceIdiom( idiom: UIUserInterfaceIdiom, ) -> Retained<UITraitCollection>
UIDevice only.Sourcepub unsafe fn userInterfaceIdiom(&self) -> UIUserInterfaceIdiom
Available on crate feature UIDevice only.
pub unsafe fn userInterfaceIdiom(&self) -> UIUserInterfaceIdiom
UIDevice only.pub fn traitCollectionWithUserInterfaceStyle( user_interface_style: UIUserInterfaceStyle, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn userInterfaceStyle(&self) -> UIUserInterfaceStyle
Available on crate feature UIInterface only.
pub unsafe fn userInterfaceStyle(&self) -> UIUserInterfaceStyle
UIInterface only.pub fn traitCollectionWithLayoutDirection( layout_direction: UITraitEnvironmentLayoutDirection, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn layoutDirection(&self) -> UITraitEnvironmentLayoutDirection
Available on crate feature UIInterface only.
pub unsafe fn layoutDirection(&self) -> UITraitEnvironmentLayoutDirection
UIInterface only.pub fn traitCollectionWithDisplayScale( scale: CGFloat, ) -> Retained<UITraitCollection>
objc2-core-foundation only.Sourcepub unsafe fn displayScale(&self) -> CGFloat
Available on crate feature objc2-core-foundation only.
pub unsafe fn displayScale(&self) -> CGFloat
objc2-core-foundation only.pub fn traitCollectionWithHorizontalSizeClass( horizontal_size_class: UIUserInterfaceSizeClass, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn horizontalSizeClass(&self) -> UIUserInterfaceSizeClass
Available on crate feature UIInterface only.
pub unsafe fn horizontalSizeClass(&self) -> UIUserInterfaceSizeClass
UIInterface only.pub fn traitCollectionWithVerticalSizeClass( vertical_size_class: UIUserInterfaceSizeClass, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn verticalSizeClass(&self) -> UIUserInterfaceSizeClass
Available on crate feature UIInterface only.
pub unsafe fn verticalSizeClass(&self) -> UIUserInterfaceSizeClass
UIInterface only.pub fn traitCollectionWithForceTouchCapability( capability: UIForceTouchCapability, ) -> Retained<UITraitCollection>
UITouch only.Sourcepub fn forceTouchCapability(&self) -> UIForceTouchCapability
Available on crate feature UITouch only.
pub fn forceTouchCapability(&self) -> UIForceTouchCapability
UITouch only.This property is not atomic.
pub fn traitCollectionWithPreferredContentSizeCategory( preferred_content_size_category: &UIContentSizeCategory, ) -> Retained<UITraitCollection>
UIContentSizeCategory only.Sourcepub unsafe fn preferredContentSizeCategory(
&self,
) -> Retained<UIContentSizeCategory>
Available on crate feature UIContentSizeCategory only.
pub unsafe fn preferredContentSizeCategory( &self, ) -> Retained<UIContentSizeCategory>
UIContentSizeCategory only.pub fn traitCollectionWithDisplayGamut( display_gamut: UIDisplayGamut, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn displayGamut(&self) -> UIDisplayGamut
Available on crate feature UIInterface only.
pub unsafe fn displayGamut(&self) -> UIDisplayGamut
UIInterface only.pub fn traitCollectionWithAccessibilityContrast( accessibility_contrast: UIAccessibilityContrast, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn accessibilityContrast(&self) -> UIAccessibilityContrast
Available on crate feature UIInterface only.
pub unsafe fn accessibilityContrast(&self) -> UIAccessibilityContrast
UIInterface only.pub fn traitCollectionWithUserInterfaceLevel( user_interface_level: UIUserInterfaceLevel, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn userInterfaceLevel(&self) -> UIUserInterfaceLevel
Available on crate feature UIInterface only.
pub unsafe fn userInterfaceLevel(&self) -> UIUserInterfaceLevel
UIInterface only.pub fn traitCollectionWithLegibilityWeight( legibility_weight: UILegibilityWeight, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn legibilityWeight(&self) -> UILegibilityWeight
Available on crate feature UIInterface only.
pub unsafe fn legibilityWeight(&self) -> UILegibilityWeight
UIInterface only.pub fn traitCollectionWithActiveAppearance( user_interface_active_appearance: UIUserInterfaceActiveAppearance, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn activeAppearance(&self) -> UIUserInterfaceActiveAppearance
Available on crate feature UIInterface only.
pub unsafe fn activeAppearance(&self) -> UIUserInterfaceActiveAppearance
UIInterface only.pub fn traitCollectionWithToolbarItemPresentationSize( toolbar_item_presentation_size: UINSToolbarItemPresentationSize, ) -> Retained<UITraitCollection>
UIInterface only.Sourcepub unsafe fn toolbarItemPresentationSize(
&self,
) -> UINSToolbarItemPresentationSize
Available on crate feature UIInterface only.
pub unsafe fn toolbarItemPresentationSize( &self, ) -> UINSToolbarItemPresentationSize
UIInterface only.Sourcepub fn traitCollectionWithImageDynamicRange(
image_dynamic_range: UIImageDynamicRange,
) -> Retained<UITraitCollection>
Available on crate feature UIInterface only.
pub fn traitCollectionWithImageDynamicRange( image_dynamic_range: UIImageDynamicRange, ) -> Retained<UITraitCollection>
UIInterface only.Construct a new trait collection with the given image content dynamic range.
Sourcepub unsafe fn imageDynamicRange(&self) -> UIImageDynamicRange
Available on crate feature UIInterface only.
pub unsafe fn imageDynamicRange(&self) -> UIImageDynamicRange
UIInterface only.The imageDynamicRange determines how HDR images will render in the given trait environment. SDR images are unaffected.
This property is not atomic.
§Safety
This might not be thread-safe.
pub fn traitCollectionWithTypesettingLanguage( language: &NSString, ) -> Retained<UITraitCollection>
Sourcepub unsafe fn typesettingLanguage(&self) -> Retained<NSString>
pub unsafe fn typesettingLanguage(&self) -> Retained<NSString>
Sourcepub fn traitCollectionWithSceneCaptureState(
scene_capture_state: UISceneCaptureState,
) -> Retained<UITraitCollection>
Available on crate feature UISceneDefinitions only.
pub fn traitCollectionWithSceneCaptureState( scene_capture_state: UISceneCaptureState, ) -> Retained<UITraitCollection>
UISceneDefinitions only.Construct a new trait collection with the given scene capture state.
Sourcepub unsafe fn sceneCaptureState(&self) -> UISceneCaptureState
Available on crate feature UISceneDefinitions only.
pub unsafe fn sceneCaptureState(&self) -> UISceneCaptureState
UISceneDefinitions only.Scene capture state represents whether a scene is currently being mirrored or recorded.
This property is not atomic.
§Safety
This might not be thread-safe.
Sourcepub fn traitCollectionWithListEnvironment(
list_environment: UIListEnvironment,
) -> Retained<UITraitCollection>
Available on crate feature UITraitListEnvironment only.
pub fn traitCollectionWithListEnvironment( list_environment: UIListEnvironment, ) -> Retained<UITraitCollection>
UITraitListEnvironment only.Construct a new trait collection with the given listEnvironment.
Sourcepub unsafe fn listEnvironment(&self) -> UIListEnvironment
Available on crate feature UITraitListEnvironment only.
pub unsafe fn listEnvironment(&self) -> UIListEnvironment
UITraitListEnvironment only.The list environment represents whether a given trait collection is from a view in a UITableView or a UICollectionView list section.
This property is not atomic.
§Safety
This might not be thread-safe.
Sourcepub fn traitCollectionWithTabAccessoryEnvironment(
tab_accessory_environment: UITabAccessoryEnvironment,
) -> Retained<UITraitCollection>
Available on crate feature UITabAccessory only.
pub fn traitCollectionWithTabAccessoryEnvironment( tab_accessory_environment: UITabAccessoryEnvironment, ) -> Retained<UITraitCollection>
UITabAccessory only.Constructs a new trait collection with the given tabAccessoryEnvironment.
Sourcepub unsafe fn tabAccessoryEnvironment(&self) -> UITabAccessoryEnvironment
Available on crate feature UITabAccessory only.
pub unsafe fn tabAccessoryEnvironment(&self) -> UITabAccessoryEnvironment
UITabAccessory only.The tab accessory environment represents whether a given trait collection is from a view in a UITabAccessory content view.
This property is not atomic.
§Safety
This might not be thread-safe.
Sourcepub unsafe fn splitViewControllerLayoutEnvironment(
&self,
) -> UISplitViewControllerLayoutEnvironment
Available on crate feature UISplitViewControllerLayoutEnvironment only.
pub unsafe fn splitViewControllerLayoutEnvironment( &self, ) -> UISplitViewControllerLayoutEnvironment
UISplitViewControllerLayoutEnvironment only.The split view controller layout environment represents whether an ancestor split view controller is expanded or collapsed.
This property is not atomic.
§Safety
This might not be thread-safe.
Sourcepub unsafe fn hdrHeadroomUsageLimit(&self) -> UIHDRHeadroomUsageLimit
Available on crate feature UIInterface only.
pub unsafe fn hdrHeadroomUsageLimit(&self) -> UIHDRHeadroomUsageLimit
UIInterface only.If HDR headroom should be used for the current UI configuration. Headroom usage is disabled in certain UI configurations, such as when all an application’s windows are in the background.
This property is not atomic.
§Safety
This might not be thread-safe.
pub fn traitCollectionWithHDRHeadroomUsageLimit( hdr_headroom_usage_limit: UIHDRHeadroomUsageLimit, ) -> Retained<UITraitCollection>
UIInterface only.pub fn traitCollectionWithResolvesNaturalAlignmentWithBaseWritingDirection( resolves_natural_alignment_with_base_writing_direction: bool, ) -> Retained<UITraitCollection>
Sourcepub unsafe fn resolvesNaturalAlignmentWithBaseWritingDirection(&self) -> bool
pub unsafe fn resolvesNaturalAlignmentWithBaseWritingDirection(&self) -> bool
Specifies the behavior for resolving NSTextAlignment.natural to the visual alignment.
When set to true, the resolved visual alignment is determined by the resolved base writing direction; otherwise, it is using the user’s preferred language.
This property is not atomic.
§Safety
This might not be thread-safe.
Source§impl UITraitCollection
Methods declared on superclass NSObject.
impl UITraitCollection
Methods declared on superclass NSObject.
Source§impl UITraitCollection
impl UITraitCollection
Sourcepub unsafe fn traitCollectionWithTraits(
mutations: UITraitMutations,
) -> Retained<UITraitCollection>
Available on crate feature block2 only.
pub unsafe fn traitCollectionWithTraits( mutations: UITraitMutations, ) -> Retained<UITraitCollection>
block2 only.§Safety
mutations must be a valid pointer.
Sourcepub unsafe fn traitCollectionByModifyingTraits(
&self,
mutations: UITraitMutations,
) -> Retained<UITraitCollection>
Available on crate feature block2 only.
pub unsafe fn traitCollectionByModifyingTraits( &self, mutations: UITraitMutations, ) -> Retained<UITraitCollection>
block2 only.§Safety
mutations must be a valid pointer.
Sourcepub unsafe fn traitCollectionWithCGFloatValue_forTrait(
value: CGFloat,
trait: &UICGFloatTrait,
) -> Retained<UITraitCollection>
Available on crate features UITrait and objc2-core-foundation only.
pub unsafe fn traitCollectionWithCGFloatValue_forTrait( value: CGFloat, trait: &UICGFloatTrait, ) -> Retained<UITraitCollection>
UITrait and objc2-core-foundation only.§Safety
trait must implement UICGFloatTraitDefinition.
Sourcepub unsafe fn traitCollectionByReplacingCGFloatValue_forTrait(
&self,
value: CGFloat,
trait: &UICGFloatTrait,
) -> Retained<UITraitCollection>
Available on crate features UITrait and objc2-core-foundation only.
pub unsafe fn traitCollectionByReplacingCGFloatValue_forTrait( &self, value: CGFloat, trait: &UICGFloatTrait, ) -> Retained<UITraitCollection>
UITrait and objc2-core-foundation only.§Safety
trait must implement UICGFloatTraitDefinition.
Sourcepub unsafe fn valueForCGFloatTrait(&self, trait: &UICGFloatTrait) -> CGFloat
Available on crate features UITrait and objc2-core-foundation only.
pub unsafe fn valueForCGFloatTrait(&self, trait: &UICGFloatTrait) -> CGFloat
UITrait and objc2-core-foundation only.§Safety
trait must implement UICGFloatTraitDefinition.
Sourcepub unsafe fn traitCollectionWithNSIntegerValue_forTrait(
value: NSInteger,
trait: &UINSIntegerTrait,
) -> Retained<UITraitCollection>
Available on crate feature UITrait only.
pub unsafe fn traitCollectionWithNSIntegerValue_forTrait( value: NSInteger, trait: &UINSIntegerTrait, ) -> Retained<UITraitCollection>
UITrait only.§Safety
trait must implement UINSIntegerTraitDefinition.
Sourcepub unsafe fn traitCollectionByReplacingNSIntegerValue_forTrait(
&self,
value: NSInteger,
trait: &UINSIntegerTrait,
) -> Retained<UITraitCollection>
Available on crate feature UITrait only.
pub unsafe fn traitCollectionByReplacingNSIntegerValue_forTrait( &self, value: NSInteger, trait: &UINSIntegerTrait, ) -> Retained<UITraitCollection>
UITrait only.§Safety
trait must implement UINSIntegerTraitDefinition.
Sourcepub unsafe fn valueForNSIntegerTrait(
&self,
trait: &UINSIntegerTrait,
) -> NSInteger
Available on crate feature UITrait only.
pub unsafe fn valueForNSIntegerTrait( &self, trait: &UINSIntegerTrait, ) -> NSInteger
UITrait only.§Safety
trait must implement UINSIntegerTraitDefinition.
Sourcepub unsafe fn traitCollectionWithObject_forTrait(
object: Option<&ProtocolObject<dyn NSObjectProtocol>>,
trait: &UIObjectTrait,
) -> Retained<UITraitCollection>
Available on crate feature UITrait only.
pub unsafe fn traitCollectionWithObject_forTrait( object: Option<&ProtocolObject<dyn NSObjectProtocol>>, trait: &UIObjectTrait, ) -> Retained<UITraitCollection>
UITrait only.§Safety
objectshould be of the correct type.traitmust implement UIObjectTraitDefinition.
Sourcepub unsafe fn traitCollectionByReplacingObject_forTrait(
&self,
object: Option<&ProtocolObject<dyn NSObjectProtocol>>,
trait: &UIObjectTrait,
) -> Retained<UITraitCollection>
Available on crate feature UITrait only.
pub unsafe fn traitCollectionByReplacingObject_forTrait( &self, object: Option<&ProtocolObject<dyn NSObjectProtocol>>, trait: &UIObjectTrait, ) -> Retained<UITraitCollection>
UITrait only.§Safety
objectshould be of the correct type.traitmust implement UIObjectTraitDefinition.
Sourcepub unsafe fn objectForTrait(
&self,
trait: &UIObjectTrait,
) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>
Available on crate feature UITrait only.
pub unsafe fn objectForTrait( &self, trait: &UIObjectTrait, ) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>
UITrait only.§Safety
trait must implement UIObjectTraitDefinition.
Source§impl UITraitCollection
CurrentTraitCollection.
impl UITraitCollection
CurrentTraitCollection.
Sourcepub unsafe fn currentTraitCollection() -> Retained<UITraitCollection>
pub unsafe fn currentTraitCollection() -> Retained<UITraitCollection>
Sourcepub unsafe fn setCurrentTraitCollection(
current_trait_collection: &UITraitCollection,
)
pub unsafe fn setCurrentTraitCollection( current_trait_collection: &UITraitCollection, )
pub fn performAsCurrentTraitCollection(&self, actions: &DynBlock<dyn Fn() + '_>)
block2 only.Source§impl UITraitCollection
DynamicAppearance.
impl UITraitCollection
DynamicAppearance.
pub fn hasDifferentColorAppearanceComparedToTraitCollection( &self, trait_collection: Option<&UITraitCollection>, ) -> bool
Source§impl UITraitCollection
ImageConfiguration.
impl UITraitCollection
ImageConfiguration.
Sourcepub unsafe fn imageConfiguration(&self) -> Retained<UIImageConfiguration>
Available on crate feature UIImageConfiguration only.
pub unsafe fn imageConfiguration(&self) -> Retained<UIImageConfiguration>
UIImageConfiguration only.Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
Available on crate feature UIIndirectScribbleInteraction only.
pub fn class(&self) -> &'static AnyClass
UIIndirectScribbleInteraction only.Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init/new methods).
§Example
Check that an instance of NSObject has the precise class NSObject.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load instead.Available on crate feature UIIndirectScribbleInteraction only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load instead.UIIndirectScribbleInteraction only.Use Ivar::load instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T.
See Ivar::load_ptr for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Available on crate feature UIIndirectScribbleInteraction only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
UIIndirectScribbleInteraction only.Attempt to downcast the object to a class of type T.
This is the reference-variant. Use Retained::downcast if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString to a NSMutableString,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass: for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject.
§Panics
This works internally by calling isKindOfClass:. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject and
NSProxy implement this method.
§Examples
Cast an NSString back and forth from NSObject.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();Try (and fail) to cast an NSObject to an NSString.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}Trait Implementations§
Source§impl AsRef<AnyObject> for UITraitCollection
impl AsRef<AnyObject> for UITraitCollection
Source§impl AsRef<NSObject> for UITraitCollection
impl AsRef<NSObject> for UITraitCollection
Source§impl AsRef<UITraitCollection> for UITraitCollection
impl AsRef<UITraitCollection> for UITraitCollection
Source§impl Borrow<AnyObject> for UITraitCollection
impl Borrow<AnyObject> for UITraitCollection
Source§impl Borrow<NSObject> for UITraitCollection
impl Borrow<NSObject> for UITraitCollection
Source§impl ClassType for UITraitCollection
impl ClassType for UITraitCollection
Source§const NAME: &'static str = "UITraitCollection"
const NAME: &'static str = "UITraitCollection"
Source§type ThreadKind = <<UITraitCollection as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<UITraitCollection as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for UITraitCollection
impl CopyingHelper for UITraitCollection
Source§type Result = UITraitCollection
type Result = UITraitCollection
Self if the type has no
immutable counterpart. Read moreSource§impl Debug for UITraitCollection
impl Debug for UITraitCollection
Source§impl DefaultRetained for UITraitCollection
impl DefaultRetained for UITraitCollection
Source§impl Deref for UITraitCollection
impl Deref for UITraitCollection
Source§impl Hash for UITraitCollection
impl Hash for UITraitCollection
Source§impl Message for UITraitCollection
impl Message for UITraitCollection
Source§impl NSCoding for UITraitCollection
impl NSCoding for UITraitCollection
Source§impl NSCopying for UITraitCollection
impl NSCopying for UITraitCollection
Source§impl NSObjectProtocol for UITraitCollection
impl NSObjectProtocol for UITraitCollection
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass directly, or cast your objects with AnyObject::downcast_ref