简体   繁体   English

如何解决 SwiftUI 中的预览错误? [X代码 13]

[英]How to solve preview bug in SwiftUI? [XCode 13]

I am using a mapkit element and want to see the preview.我正在使用mapkit元素并希望查看预览。 But, the preview option provided by Xcode is showing wrong color for map annotations.但是,Xcode 提供的预览选项显示 map 注释的颜色错误。

For example, If I set annotation color as yellow, In preview I'm getting blue color.例如,如果我将注释颜色设置为黄色,在预览中我会得到蓝色。

Sample code:示例代码:

Map(coordinateRegion: $region, annotationItems: locations, annotationContent: { item in
            // a. Old style, always static
            MapPin(coordinate: item.location, tint: .accentColor)
        })

Note my accent color is: yellow.请注意,我的强调色是:黄色。

Is there any solution to solve this preview bug?有什么解决方案可以解决这个预览错误吗?

Well.出色地。 I have found that there is no problem in the code.我发现代码没有问题。

It can be a bug of XCode 13.2.1's preview system.这可能是 XCode 13.2.1 的预览系统的错误。 Because I have got the correct output using simulator without changing anything in the code.因为我使用模拟器得到了正确的 output 而无需更改代码中的任何内容。 So, nothing to worry at all if you face this kind of issue sometimes.因此,如果您有时遇到此类问题,完全不用担心。

Still, if anyone have anything to share on top my answer, you are welcome.不过,如果有人在我的回答之上有什么要分享的,欢迎您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM