#[repr(C)]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 unsafe fn init(this: Allocated<Self>) -> Retained<Self>
pub unsafe fn initWithCoder( this: Allocated<Self>, coder: &NSCoder, ) -> Option<Retained<Self>>
pub unsafe fn containsTraitsInCollection( &self, trait: Option<&UITraitCollection>, ) -> bool
pub unsafe fn traitCollectionWithTraitsFromCollections( trait_collections: &NSArray<UITraitCollection>, ) -> Retained<UITraitCollection>
pub unsafe fn traitCollectionWithUserInterfaceIdiom( idiom: UIUserInterfaceIdiom, ) -> Retained<UITraitCollection>
UIDevice only.pub unsafe fn userInterfaceIdiom(&self) -> UIUserInterfaceIdiom
UIDevice only.pub unsafe fn traitCollectionWithUserInterfaceStyle( user_interface_style: UIUserInterfaceStyle, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn userInterfaceStyle(&self) -> UIUserInterfaceStyle
UIInterface only.pub unsafe fn traitCollectionWithLayoutDirection( layout_direction: UITraitEnvironmentLayoutDirection, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn layoutDirection(&self) -> UITraitEnvironmentLayoutDirection
UIInterface only.pub unsafe fn traitCollectionWithDisplayScale( scale: CGFloat, ) -> Retained<UITraitCollection>
objc2-core-foundation only.pub unsafe fn displayScale(&self) -> CGFloat
objc2-core-foundation only.pub unsafe fn traitCollectionWithHorizontalSizeClass( horizontal_size_class: UIUserInterfaceSizeClass, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn horizontalSizeClass(&self) -> UIUserInterfaceSizeClass
UIInterface only.pub unsafe fn traitCollectionWithVerticalSizeClass( vertical_size_class: UIUserInterfaceSizeClass, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn verticalSizeClass(&self) -> UIUserInterfaceSizeClass
UIInterface only.pub unsafe fn traitCollectionWithForceTouchCapability( capability: UIForceTouchCapability, ) -> Retained<UITraitCollection>
UITouch only.pub fn forceTouchCapability(&self) -> UIForceTouchCapability
UITouch only.pub unsafe fn traitCollectionWithPreferredContentSizeCategory( preferred_content_size_category: &UIContentSizeCategory, ) -> Retained<UITraitCollection>
UIContentSizeCategory only.pub unsafe fn preferredContentSizeCategory( &self, ) -> Retained<UIContentSizeCategory>
UIContentSizeCategory only.pub unsafe fn traitCollectionWithDisplayGamut( display_gamut: UIDisplayGamut, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn displayGamut(&self) -> UIDisplayGamut
UIInterface only.pub unsafe fn traitCollectionWithAccessibilityContrast( accessibility_contrast: UIAccessibilityContrast, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn accessibilityContrast(&self) -> UIAccessibilityContrast
UIInterface only.pub unsafe fn traitCollectionWithUserInterfaceLevel( user_interface_level: UIUserInterfaceLevel, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn userInterfaceLevel(&self) -> UIUserInterfaceLevel
UIInterface only.pub unsafe fn traitCollectionWithLegibilityWeight( legibility_weight: UILegibilityWeight, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn legibilityWeight(&self) -> UILegibilityWeight
UIInterface only.pub unsafe fn traitCollectionWithActiveAppearance( user_interface_active_appearance: UIUserInterfaceActiveAppearance, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn activeAppearance(&self) -> UIUserInterfaceActiveAppearance
UIInterface only.pub unsafe fn traitCollectionWithToolbarItemPresentationSize( toolbar_item_presentation_size: UINSToolbarItemPresentationSize, ) -> Retained<UITraitCollection>
UIInterface only.pub unsafe fn toolbarItemPresentationSize( &self, ) -> UINSToolbarItemPresentationSize
UIInterface only.Sourcepub unsafe fn traitCollectionWithImageDynamicRange(
image_dynamic_range: UIImageDynamicRange,
) -> Retained<UITraitCollection>
Available on crate feature UIInterface only.
pub unsafe 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.
pub unsafe fn traitCollectionWithTypesettingLanguage( language: &NSString, ) -> Retained<UITraitCollection>
pub unsafe fn typesettingLanguage(&self) -> Retained<NSString>
Sourcepub unsafe fn traitCollectionWithSceneCaptureState(
scene_capture_state: UISceneCaptureState,
) -> Retained<UITraitCollection>
Available on crate feature UISceneDefinitions only.
pub unsafe 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.
Sourcepub unsafe fn traitCollectionWithListEnvironment(
list_environment: UIListEnvironment,
) -> Retained<UITraitCollection>
Available on crate feature UITraitListEnvironment only.
pub unsafe 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.
Source§impl UITraitCollection
Methods declared on superclass NSObject.
impl UITraitCollection
Methods declared on superclass NSObject.
Source§impl UITraitCollection
impl UITraitCollection
pub unsafe fn traitCollectionWithTraits( mutations: UITraitMutations, ) -> Retained<UITraitCollection>
block2 only.pub unsafe fn traitCollectionByModifyingTraits( &self, mutations: UITraitMutations, ) -> Retained<UITraitCollection>
block2 only.pub unsafe fn traitCollectionWithCGFloatValue_forTrait( value: CGFloat, trait: &UICGFloatTrait, ) -> Retained<UITraitCollection>
UITrait and objc2-core-foundation only.pub unsafe fn traitCollectionByReplacingCGFloatValue_forTrait( &self, value: CGFloat, trait: &UICGFloatTrait, ) -> Retained<UITraitCollection>
UITrait and objc2-core-foundation only.pub unsafe fn valueForCGFloatTrait(&self, trait: &UICGFloatTrait) -> CGFloat
UITrait and objc2-core-foundation only.pub unsafe fn traitCollectionWithNSIntegerValue_forTrait( value: NSInteger, trait: &UINSIntegerTrait, ) -> Retained<UITraitCollection>
UITrait only.pub unsafe fn traitCollectionByReplacingNSIntegerValue_forTrait( &self, value: NSInteger, trait: &UINSIntegerTrait, ) -> Retained<UITraitCollection>
UITrait only.pub unsafe fn valueForNSIntegerTrait( &self, trait: &UINSIntegerTrait, ) -> NSInteger
UITrait only.pub unsafe fn traitCollectionWithObject_forTrait( object: Option<&ProtocolObject<dyn NSObjectProtocol>>, trait: &UIObjectTrait, ) -> Retained<UITraitCollection>
UITrait only.pub unsafe fn traitCollectionByReplacingObject_forTrait( &self, object: Option<&ProtocolObject<dyn NSObjectProtocol>>, trait: &UIObjectTrait, ) -> Retained<UITraitCollection>
UITrait only.pub unsafe fn objectForTrait( &self, trait: &UIObjectTrait, ) -> Option<Retained<ProtocolObject<dyn NSObjectProtocol>>>
UITrait only.Source§impl UITraitCollection
CurrentTraitCollection.
impl UITraitCollection
CurrentTraitCollection.
pub unsafe fn currentTraitCollection() -> Retained<UITraitCollection>
Sourcepub unsafe fn setCurrentTraitCollection(
current_trait_collection: &UITraitCollection,
)
pub unsafe fn setCurrentTraitCollection( current_trait_collection: &UITraitCollection, )
Setter for currentTraitCollection.
pub unsafe fn performAsCurrentTraitCollection( &self, actions: &Block<dyn Fn() + '_>, )
block2 only.Source§impl UITraitCollection
DynamicAppearance.
impl UITraitCollection
DynamicAppearance.
pub unsafe fn hasDifferentColorAppearanceComparedToTraitCollection( &self, trait_collection: Option<&UITraitCollection>, ) -> bool
Source§impl UITraitCollection
ImageConfiguration.
impl UITraitCollection
ImageConfiguration.
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.
§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 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