简体   繁体   English

iOS14 小部件的模糊背景

[英]Blur Background for iOS14 Widgets

I've created some iOS14 Widgets and set a Rectangle with a custom Image as Background for it.我创建了一些 iOS14 小部件,并设置了一个带有自定义图像的矩形作为它的背景。 It have a corner Radius and a padding to all sides.它有一个角半径和所有边的填充。

The Result is a black Background behind my custom Background and I don't know how to make it blur like other Widgets (for example the Shortcuts Widget you see in the picture at the bottom).结果是我的自定义背景后面是黑色背景,我不知道如何让它像其他小部件一样模糊(例如您在底部图片中看到的快捷方式小部件)。

Has anyone an idea what I can do?有谁知道我能做什么?

在此处输入图像描述

Update:更新:

Ok I figured out that you can change the background color in the Widget struct itself.好的,我发现您可以更改 Widget 结构本身的背景颜色。 A nice way is to set the colors you want in Assets Catalog from the Widget -> WidgetBackground and add the following code in the struct:一个不错的方法是在 Widget -> WidgetBackground 的 Assets Catalog 中设置你想要的 colors 并在结构中添加以下代码:

@main
struct CoreDataWidget: Widget {
    let kind: String = "CoreDataWidget"

    var body: some WidgetConfiguration {
        StaticConfiguration(kind: kind, provider: HomeWidgetTimeline()) { entry in
            HomeWidgetEntryView(entry: entry)
                .background(Color("WidgetBackground")) // <- this line

        }
        .configurationDisplayName("OhMyMoney")
        .description("You want to know your current Money and add Expenses quickly with one Touch? \nThen use this Widget!".localized())
        .supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
    }
}

But is there a way to make the background transparent like the Shortcuts Widget from the picture above?但是有没有办法像上图中的Shortcuts Widget一样使背景透明?

It's impossible:(不可能:(

3rd Party Apps cannot use blurred backgrounds for their Widgets第三方应用程序不能为其小部件使用模糊背景

https://developer.apple.com/forums/thread/655990 https://developer.apple.com/forums/thread/655990

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

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