UIView的神秘UIColor行为,通常在Swift中

问题描述 投票:0回答:1

最近我在Swift中遇到了一个有关UIColor的有趣(可能是幼稚的)问题。

import UIKit

let view = UIView(frame: CGRect(x: 0,
                                y: 0,
                                width: 50,
                                height: 50))
view.backgroundColor = .systemBlue

let a = UIColor.systemBlue
switch a {
case .red:
    print("red")
case .systemBlue:
    print("blue")
default:
    print("unknown")
}

下面的代码在操场上完全打印出“蓝色”,但是不断变化

let a = UIColor.systemBlue
to
let a = view.backgroundColor ?? .red

在操场上打印“未知”,有人可以帮忙这里发生的事情吗?我无法解决它。在某个时候它与值类型或引用类型有关吗?请帮忙!

swift uiview uikit uicolor swift-playground
1个回答
0
投票
print(UIColor.systemBlue) <UIDynamicSystemColor: 0x600000b47880; name = systemBlueColor >
© www.soinside.com 2019 - 2024. All rights reserved.