iOS 11.x system colors
2089 观看
2回复
218 作者的声誉
I've read a lot of posts on how to customize Views colors, but nothing about retrieving system colors for standard controls like the Navigation Bar, Status Bar and Tab Bar in iOS 11.x or previous. The class UIColor has 3 system colors but they are pretty useless. Calling UINavigationBar.appearance(), for example, is of little help because it'll probably return the "clear" color for the default light color scheme, in case nothing has been defined in the application plist. So why doesn't Apple supply a way to programmatically get the system colors as others do (for Windows and Android) ? Has anybody any idea where to find them ? Tx in advance.
作者: Sergiob 的来源 发布者: 2017 年 12 月 27 日回应 2
5像
7628 作者的声誉
iOS does not provide a way to access these colors programmatically.
Instead, it's simple enough to add these colors to your own project. If the colors change in a future iOS version (and you want to use those new colors instead), you will need to update your app.
In most cases, this is not an issue since apps define their own colors for branding purposes.
enum SystemColor {
case red
case orange
case yellow
case green
case tealBlue
case blue
case purple
case pink
var uiColor: UIColor {
switch self {
case .red:
return UIColor(red: 255/255, green: 59/255, blue: 48/255, alpha: 1)
case .orange:
return UIColor(red: 255/255, green: 149/255, blue: 0/255, alpha: 1)
case .yellow:
return UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1)
case .green:
return UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
case .tealBlue:
return UIColor(red: 90/255, green: 200/255, blue: 250/255, alpha: 1)
case .blue:
return UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
case .purple:
return UIColor(red: 88/255, green: 86/255, blue: 214/255, alpha: 1)
case .pink:
return UIColor(red: 255/255, green: 45/255, blue: 85/255, alpha: 1)
}
}
}
Sample usage:
myView.backgroundColor = SystemColor.blue.uiColor
If you prefer, these colors could also be defined as an extension on UIColor
like so:
extension UIColor {
static let systemBlue = UIColor(red: 0/255, green: 122/255, blue: 255/255, alpha: 1)
// etc
}
and the usage would look like this:
UIColor.systemBlue
Colors in the Human Interface Guidelines
作者: nathangitter 发布者: 2017 年 12 月 27 日0像
2170 作者的声誉
Since Xcode 11.0 you can use UIColor.systemRed
, UIColor.systemGreen
, UIColor.systemBlue
and other UIColor.system*
properties to solve the issue you described.
来自类别的问题 :
- ios iPhone app in landscape mode, 2008 systems
- ios 如何为我的网站提供iPhone的图标?
- ios 如何调整UITextView的内容大小?
- ios iPhone viewWillAppear没有开火
- ios 如何在顶部状态栏中显示加载指示器
- swift 如何以编程方式确定我的应用程序是否在iphone模拟器中运行?
- swift iOS:将UTC NSDate转换为本地时区
- swift 如何在运行时为UIBarButtonItem设置目标和操作
- swift 单个UILabel中的粗体和非粗体文字?
- swift 找到三次贝塞尔曲线上的点的切线
- colors Function for creating color wheels
- colors 随机生成美观的调色板的算法
- colors 色盲模拟器
- colors 如何在交互式调试期间突出显示和着色gdb输出?
- colors 有人可以推荐Delphi的颜色选择器组件吗?
- controls 在Windows窗体中访问另一个窗体上的控件的最佳方法?
- controls 如何按名称或类型查找WPF控件?
- controls 如何将WPF选项卡项标题拉伸到父控件宽度
- controls ZedGraph标签
- controls WPF Numeric UpDown控件在哪里?