访问系统.破坏性的红色按钮颜色 [英] Accessing the system .Destructive red button color

查看:24
本文介绍了访问系统.破坏性的红色按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问用于破坏性警报按钮样式的系统红色?

How do you access the system red color used for the destructive alert button style?

例如,用于按钮的默认样式蓝色可以在 Swift 中通过 let systemBlueColor = view.tintColor 访问,它对应于 UIColor(red: 0, green: 122,蓝色:255,alpha:1.0).

For instance, the default style blue color used for buttons can be accessed in Swift by let systemBlueColor = view.tintColor, which corresponds to UIColor(red: 0, green: 122, blue: 255, alpha: 1.0).

破坏性的红色似乎是由 UIColor(red: 255, green: 59, blue: 48, alpha: 1.0) 给出的,但是有没有办法以类似的方式访问它默认的 view.tintColor 方法?

The destructive red color seems to be given by UIColor(red: 255, green: 59, blue: 48, alpha: 1.0) but is there any way to access it in a similar way to the default view.tintColor method?

我了解到 RGB 解释可能因设备/操作系统而异,因此我想访问与设备/操作系统无关的颜色版本.

I have read that RGB interpretations can vary on devices / operating systems, so I would like to access the device / operating system independent version of the color.

推荐答案

UIColor 上有一个未公开的类方法,名为 _systemDestructiveTintColor,它将返回您需要的颜色:

There is an undocumented class method on UIColor called _systemDestructiveTintColor which will return the color you need:

let red = UIColor.performSelector("_systemDestructiveTintColor").takeUnretainedValue()

它返回一个非托管对象,您必须对其调用 .takeUnretainedValue(),因为颜色所有权尚未转移到我们自己的对象.

It returns an unmanaged object, which you must call .takeUnretainedValue() on, since the color ownership has not been transferred to our own object.

与任何未记录的 API 一样,尝试使用此方法时应谨慎:

As with any undocumented API, you should take caution when trying to use this method:

斯威夫特 5:

if UIColor.responds(to: Selector(("_systemDestructiveTintColor"))) {
    if let red = UIColor.perform(Selector(("_systemDestructiveTintColor")))?.takeUnretainedValue() as? UIColor {
        // use the color
    }
}

以前的 Swift 版本:

Previous Swift versions:

if UIColor.respondsToSelector("_systemDestructiveTintColor") {
    if let red = UIColor.performSelector("_systemDestructiveTintColor").takeUnretainedValue() as? UIColor {
        // use the color
    }
}

这个和其他颜色可以在 UIColor 标题.

This and other colors can be found in the UIColor header.

这篇关于访问系统.破坏性的红色按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆