有人能告诉我如何在 SwiftUI 列表上添加渐变背景吗?
当前代码:
struct TestView: View {
var body: some View {
LinearGradient(gradient: Gradient(colors: [Color.red, Color.purple]), startPoint: .top, endPoint: .bottom)
.edgesIgnoringSafeArea(.vertical)
.overlay(
List {
Group {
Text("Hallo")
Text("World")
}
.background(Color.blue)
}
.background(Color.green)
.padding(50)
)
}
}
Run Code Online (Sandbox Code Playgroud)
当前布局,其中渐变在单元格后面可见。我想让单元格透明以查看下面的渐变。
谢谢!
有人知道如何在 iOS 10 中创建原子布尔值吗?
当前代码:
import UIKit
struct AtomicBoolean {
fileprivate var val: UInt8 = 0
/// Sets the value, and returns the previous value.
/// The test/set is an atomic operation.
mutating func testAndSet(_ value: Bool) -> Bool {
if value {
return OSAtomicTestAndSet(0, &val)
} else {
return OSAtomicTestAndClear(0, &val)
}
}
/// Returns the current value of the boolean.
/// The value may change before this method returns.
func test() -> Bool {
return val != 0 …Run Code Online (Sandbox Code Playgroud)