【发布时间】:2021-03-08 23:14:56
【问题描述】:
我创建了一些 iOS14 小部件,并为其设置了一个带有自定义图像的矩形作为背景。 它有一个角半径和一个边距。
结果是我的自定义背景后面的黑色背景,我不知道如何使它像其他小部件一样模糊(例如您在底部图片中看到的快捷方式小部件)。
有人知道我能做什么吗?
更新:
好的,我发现您可以更改 Widget 结构本身的背景颜色。一个不错的方法是从 Widget -> WidgetBackground 在 Assets Catalog 中设置您想要的颜色,并在结构中添加以下代码:
@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])
}
}
但是有没有办法像上图的 Shortcuts Widget 一样让背景透明?
【问题讨论】:
标签: swift swiftui background widget ios14