기존 색상을 그대로 쓰려고하니 에러발생
.foregroundColor(UIColor.systemBlue)
// Cannot convert value of type 'UIColor' to expected argument type 'Color?'
그냥 Color() 생성자를 쓰면 바로 바꿔진다
.foregroundColor(Color(UIColor.systemBlue))
도대체 왜 그냥 자동고침으로 변경이 안되는걸까?...
참고로 저 Color의 생성자는 아래와같이 선언되어있다.
extension Color {
/// Creates a color from a UIKit color.
///
/// Use this method to create a SwiftUI color from a
/// <doc://com.apple.documentation/documentation/UIKit/UIColor> instance.
/// The new color preserves the adaptability of the original.
/// For example, you can create a rectangle using
/// <doc://com.apple.documentation/documentation/UIKit/UIColor/3173132-link>
/// to see how the shade adjusts to match the user's system settings:
///
/// struct Box: View {
/// var body: some View {
/// Color(UIColor.link)
/// .frame(width: 200, height: 100)
/// }
/// }
///
/// The `Box` view defined above automatically changes its
/// appearance when the user turns on Dark Mode. With the light and dark
/// appearances placed side by side, you can see the subtle difference
/// in shades:
///
/// 
///
/// > Note: Use this initializer only if you need to convert an existing
/// <doc://com.apple.documentation/documentation/UIKit/UIColor> to a
/// SwiftUI color. Otherwise, create a SwiftUI ``Color`` using an
/// initializer like ``init(_:red:green:blue:opacity:)``, or use a system
/// color like ``ShapeStyle/blue``.
///
/// - Parameter color: A
/// <doc://com.apple.documentation/documentation/UIKit/UIColor> instance
/// from which to create a color.
public init(_ color: UIColor)
}
반응형
'iOS > swift' 카테고리의 다른 글
CoreData with SwiftUI (0) | 2025.05.09 |
---|---|
[swiftUI]Static method 'buildExpression' requires ~ (0) | 2025.04.22 |
background audio play - 5 [SwiftUI로 변경] (0) | 2025.03.26 |
background audio play - 4 [mvvm 패턴] (1) | 2024.11.27 |
background audio play - 3 [제어센터에서의 컨트롤] (5) | 2024.11.10 |