pub struct UIColor { /* private fields */ }UIColor only.Expand description
Implementations§
Source§impl UIColor
UIAccessibility.
impl UIColor
UIAccessibility.
Sourcepub unsafe fn accessibilityName(&self) -> Retained<NSString>
Available on crate feature UIAccessibilityAdditions only.
pub unsafe fn accessibilityName(&self) -> Retained<NSString>
UIAccessibilityAdditions only.Source§impl UIColor
impl UIColor
pub fn colorWithWhite_alpha(white: CGFloat, alpha: CGFloat) -> Retained<UIColor>
objc2-core-foundation only.pub fn colorWithHue_saturation_brightness_alpha( hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn colorWithRed_green_blue_alpha( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn colorWithDisplayP3Red_green_blue_alpha( display_p3_red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn colorWithCGColor(cg_color: &CGColor) -> Retained<UIColor>
objc2-core-graphics only.pub fn colorWithPatternImage(image: &UIImage) -> Retained<UIColor>
UIImage only.pub fn colorWithCIColor(ci_color: &CIColor) -> Retained<UIColor>
objc2-core-image and non-watchOS only.pub fn initWithWhite_alpha( this: Allocated<Self>, white: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn initWithHue_saturation_brightness_alpha( this: Allocated<Self>, hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn initWithRed_green_blue_alpha( this: Allocated<Self>, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn initWithDisplayP3Red_green_blue_alpha( this: Allocated<Self>, display_p3_red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.pub fn initWithCGColor( this: Allocated<Self>, cg_color: &CGColor, ) -> Retained<UIColor>
objc2-core-graphics only.pub fn initWithPatternImage( this: Allocated<Self>, image: &UIImage, ) -> Retained<UIColor>
UIImage only.pub fn initWithCIColor( this: Allocated<Self>, ci_color: &CIColor, ) -> Retained<UIColor>
objc2-core-image and non-watchOS only.Sourcepub fn initWithRed_green_blue_alpha_exposure(
this: Allocated<Self>,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
exposure: CGFloat,
) -> Retained<UIColor>
Available on crate feature objc2-core-foundation only.
pub fn initWithRed_green_blue_alpha_exposure( this: Allocated<Self>, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, exposure: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.Generates an HDR color by applying an exposure to the SDR color defined by the red, green, and blue components. The red, green, and blue components have a nominal range of [0..1], exposure is a value >= 0. To produce an HDR color, we process the given color in a linear color space, multiplying component values by 2^exposure. The produced color will have a contentHeadroom equal to the linearized exposure value. Each whole value of exposure produces a color that is twice as bright.
pub fn colorWithRed_green_blue_alpha_exposure( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, exposure: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.Sourcepub fn initWithRed_green_blue_alpha_linearExposure(
this: Allocated<Self>,
red: CGFloat,
green: CGFloat,
blue: CGFloat,
alpha: CGFloat,
linear_exposure: CGFloat,
) -> Retained<UIColor>
Available on crate feature objc2-core-foundation only.
pub fn initWithRed_green_blue_alpha_linearExposure( this: Allocated<Self>, red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, linear_exposure: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.Generates an HDR color by applying an exposure to the SDR color defined by the red, green, and blue components. The red, green, and blue components have a nominal range of [0..1], linearExposure is a value >= 1. To produce an HDR color, we process the given color in a linear color space, multiplying component values by linearExposure . The produced color will have a contentHeadroom equal to linearExposure. Each doubling of linearExposure produces a color that is twice as bright.
pub fn colorWithRed_green_blue_alpha_linearExposure( red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat, linear_exposure: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.Sourcepub fn colorByApplyingContentHeadroom(
&self,
content_headroom: CGFloat,
) -> Retained<UIColor>
Available on crate feature objc2-core-foundation only.
pub fn colorByApplyingContentHeadroom( &self, content_headroom: CGFloat, ) -> Retained<UIColor>
objc2-core-foundation only.Reinterpret the color by applying a new contentHeadroom without changing the color components. Changing the contentHeadroom redefines the color relative to a different peak white, changing its behavior under tone mapping and the result of calling standardDynamicRangeColor. The new color will have a contentHeadroom >= 1.0.
pub fn blackColor() -> Retained<UIColor>
pub fn darkGrayColor() -> Retained<UIColor>
pub fn lightGrayColor() -> Retained<UIColor>
pub fn whiteColor() -> Retained<UIColor>
pub fn grayColor() -> Retained<UIColor>
pub fn redColor() -> Retained<UIColor>
pub fn greenColor() -> Retained<UIColor>
pub fn blueColor() -> Retained<UIColor>
pub fn cyanColor() -> Retained<UIColor>
pub fn yellowColor() -> Retained<UIColor>
pub fn magentaColor() -> Retained<UIColor>
pub fn orangeColor() -> Retained<UIColor>
pub fn purpleColor() -> Retained<UIColor>
pub fn brownColor() -> Retained<UIColor>
pub fn clearColor() -> Retained<UIColor>
pub fn set(&self)
pub fn setFill(&self)
pub fn setStroke(&self)
Sourcepub unsafe fn getWhite_alpha(
&self,
white: *mut CGFloat,
alpha: *mut CGFloat,
) -> bool
Available on crate feature objc2-core-foundation only.
pub unsafe fn getWhite_alpha( &self, white: *mut CGFloat, alpha: *mut CGFloat, ) -> bool
objc2-core-foundation only.§Safety
whitemust be a valid pointer or null.alphamust be a valid pointer or null.
Sourcepub unsafe fn getHue_saturation_brightness_alpha(
&self,
hue: *mut CGFloat,
saturation: *mut CGFloat,
brightness: *mut CGFloat,
alpha: *mut CGFloat,
) -> bool
Available on crate feature objc2-core-foundation only.
pub unsafe fn getHue_saturation_brightness_alpha( &self, hue: *mut CGFloat, saturation: *mut CGFloat, brightness: *mut CGFloat, alpha: *mut CGFloat, ) -> bool
objc2-core-foundation only.§Safety
huemust be a valid pointer or null.saturationmust be a valid pointer or null.brightnessmust be a valid pointer or null.alphamust be a valid pointer or null.
Sourcepub unsafe fn getRed_green_blue_alpha(
&self,
red: *mut CGFloat,
green: *mut CGFloat,
blue: *mut CGFloat,
alpha: *mut CGFloat,
) -> bool
Available on crate feature objc2-core-foundation only.
pub unsafe fn getRed_green_blue_alpha( &self, red: *mut CGFloat, green: *mut CGFloat, blue: *mut CGFloat, alpha: *mut CGFloat, ) -> bool
objc2-core-foundation only.§Safety
redmust be a valid pointer or null.greenmust be a valid pointer or null.bluemust be a valid pointer or null.alphamust be a valid pointer or null.
pub fn colorWithAlphaComponent(&self, alpha: CGFloat) -> Retained<UIColor>
objc2-core-foundation only.Sourcepub unsafe fn CGColor(&self) -> Retained<CGColor>
Available on crate feature objc2-core-graphics only.
pub unsafe fn CGColor(&self) -> Retained<CGColor>
objc2-core-graphics only.Sourcepub unsafe fn CIColor(&self) -> Retained<CIColor>
Available on crate feature objc2-core-image and non-watchOS only.
pub unsafe fn CIColor(&self) -> Retained<CIColor>
objc2-core-image and non-watchOS only.Sourcepub unsafe fn linearExposure(&self) -> CGFloat
Available on crate feature objc2-core-foundation only.
pub unsafe fn linearExposure(&self) -> CGFloat
objc2-core-foundation only.The linear brightness multiplier that was applied when generating this color. Colors created with an exposure by UIColor create CGColors that are tagged with a contentHeadroom value. While CGColors created without a contentHeadroom tag will return 0 from CGColorGetHeadroom, UIColors generated in a similar fashion return a linearExposure of 1.0.
This property is not atomic.
§Safety
This might not be thread-safe.
Sourcepub unsafe fn standardDynamicRangeColor(&self) -> Retained<UIColor>
pub unsafe fn standardDynamicRangeColor(&self) -> Retained<UIColor>
In some cases it is useful to recover the color that was base SDR color that was exposed to generate the given HDR color. If a color’s linearExposure is >1, then this will return the base SDR color.
This property is not atomic.
§Safety
This might not be thread-safe.
impl UIColor
UINSItemProvider.
Source§impl UIColor
UIColorNamedColors.
impl UIColor
UIColorNamedColors.
pub fn colorNamed(name: &NSString) -> Option<Retained<UIColor>>
pub fn colorNamed_inBundle_compatibleWithTraitCollection( name: &NSString, bundle: Option<&NSBundle>, trait_collection: Option<&UITraitCollection>, ) -> Option<Retained<UIColor>>
UITraitCollection only.Source§impl UIColor
DynamicColors.
impl UIColor
DynamicColors.
Sourcepub unsafe fn colorWithDynamicProvider(
dynamic_provider: &DynBlock<dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>>,
) -> Retained<UIColor>
Available on crate features UITraitCollection and block2 only.
pub unsafe fn colorWithDynamicProvider( dynamic_provider: &DynBlock<dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>>, ) -> Retained<UIColor>
UITraitCollection and block2 only.§Safety
dynamic_provider block’s return must be a valid pointer.
Sourcepub unsafe fn initWithDynamicProvider(
this: Allocated<Self>,
dynamic_provider: &DynBlock<dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>>,
) -> Retained<UIColor>
Available on crate features UITraitCollection and block2 only.
pub unsafe fn initWithDynamicProvider( this: Allocated<Self>, dynamic_provider: &DynBlock<dyn Fn(NonNull<UITraitCollection>) -> NonNull<UIColor>>, ) -> Retained<UIColor>
UITraitCollection and block2 only.§Safety
dynamic_provider block’s return must be a valid pointer.
pub fn resolvedColorWithTraitCollection( &self, trait_collection: &UITraitCollection, ) -> Retained<UIColor>
UITraitCollection only.Source§impl UIColor
ProminenceSupport.
impl UIColor
ProminenceSupport.
pub fn colorWithProminence( &self, prominence: UIColorProminence, ) -> Retained<UIColor>
Sourcepub unsafe fn prominence(&self) -> UIColorProminence
pub unsafe fn prominence(&self) -> UIColorProminence
Source§impl UIColor
UIColorSystemColors.
impl UIColor
UIColorSystemColors.
pub fn systemRedColor() -> Retained<UIColor>
UIInterface only.pub fn systemGreenColor() -> Retained<UIColor>
UIInterface only.pub fn systemBlueColor() -> Retained<UIColor>
UIInterface only.pub fn systemOrangeColor() -> Retained<UIColor>
UIInterface only.pub fn systemYellowColor() -> Retained<UIColor>
UIInterface only.pub fn systemPinkColor() -> Retained<UIColor>
UIInterface only.pub fn systemPurpleColor() -> Retained<UIColor>
UIInterface only.pub fn systemTealColor() -> Retained<UIColor>
UIInterface only.pub fn systemIndigoColor() -> Retained<UIColor>
UIInterface only.pub fn systemBrownColor() -> Retained<UIColor>
UIInterface only.pub fn systemMintColor() -> Retained<UIColor>
UIInterface only.pub fn systemCyanColor() -> Retained<UIColor>
UIInterface only.pub fn systemGrayColor() -> Retained<UIColor>
UIInterface only.pub fn systemGray2Color() -> Retained<UIColor>
UIInterface only.pub fn systemGray3Color() -> Retained<UIColor>
UIInterface only.pub fn systemGray4Color() -> Retained<UIColor>
UIInterface only.pub fn systemGray5Color() -> Retained<UIColor>
UIInterface only.pub fn systemGray6Color() -> Retained<UIColor>
UIInterface only.pub fn tintColor() -> Retained<UIColor>
UIInterface only.pub fn labelColor() -> Retained<UIColor>
UIInterface only.pub fn secondaryLabelColor() -> Retained<UIColor>
UIInterface only.pub fn tertiaryLabelColor() -> Retained<UIColor>
UIInterface only.pub fn quaternaryLabelColor() -> Retained<UIColor>
UIInterface only.pub fn linkColor() -> Retained<UIColor>
UIInterface only.pub fn placeholderTextColor() -> Retained<UIColor>
UIInterface only.pub fn separatorColor() -> Retained<UIColor>
UIInterface only.pub fn opaqueSeparatorColor() -> Retained<UIColor>
UIInterface only.pub fn systemBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn secondarySystemBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn tertiarySystemBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn systemGroupedBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn secondarySystemGroupedBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn tertiarySystemGroupedBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn systemFillColor() -> Retained<UIColor>
UIInterface only.pub fn secondarySystemFillColor() -> Retained<UIColor>
UIInterface only.pub fn tertiarySystemFillColor() -> Retained<UIColor>
UIInterface only.pub fn quaternarySystemFillColor() -> Retained<UIColor>
UIInterface only.pub fn lightTextColor() -> Retained<UIColor>
UIInterface only.pub fn darkTextColor() -> Retained<UIColor>
UIInterface only.pub fn groupTableViewBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn viewFlipsideBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn scrollViewTexturedBackgroundColor() -> Retained<UIColor>
UIInterface only.pub fn underPageBackgroundColor() -> Retained<UIColor>
UIInterface 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 ClassType for UIColor
impl ClassType for UIColor
Source§const NAME: &'static str = "UIColor"
const NAME: &'static str = "UIColor"
Source§type ThreadKind = <<UIColor as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<UIColor as ClassType>::Super as ClassType>::ThreadKind
Source§impl CopyingHelper for UIColor
impl CopyingHelper for UIColor
Source§impl DefaultRetained for UIColor
impl DefaultRetained for UIColor
Source§impl NSCopying for UIColor
impl NSCopying for UIColor
Source§impl NSItemProviderReading for UIColor
impl NSItemProviderReading for UIColor
Source§impl NSItemProviderWriting for UIColor
impl NSItemProviderWriting for UIColor
fn writableTypeIdentifiersForItemProvider_class() -> Retained<NSArray<NSString>>
fn writableTypeIdentifiersForItemProvider(&self) -> Retained<NSArray<NSString>>
fn itemProviderVisibilityForRepresentationWithTypeIdentifier_class( type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
fn itemProviderVisibilityForRepresentationWithTypeIdentifier( &self, type_identifier: &NSString, ) -> NSItemProviderRepresentationVisibility
Source§impl NSObjectProtocol for UIColor
impl NSObjectProtocol for UIColor
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