戴铭

Results 93 issues of 戴铭

![](https://user-images.githubusercontent.com/251980/156298284-2fb37b3e-55f0-4918-ba8e-74f747bf3171.jpeg) 有 Picker 视图,还有颜色和时间选择的 ColorPicker 和 DatePicker。 示例代码如下: ```swift struct PlayPickerView: View { @State private var select = 1 @State private var color = Color.red.opacity(0.3) var dateFt: DateFormatter { let...

![](https://user-images.githubusercontent.com/251980/156332122-66813e4e-851c-4207-8cb9-b41ea0365008.jpeg) ```swift struct PlayEffect: View { @State private var isHover = false var body: some View { ZStack { LinearGradient(colors: [.purple, .black, .pink], startPoint: .top, endPoint: .bottom).ignoresSafeArea() VStack(spacing: 20) {...

```swift struct PlayColor: View { var body: some View { ZStack { Color.black.edgesIgnoringSafeArea(.all) // Color 也是一个 View VStack(spacing: 10) { Text("这是一个适配了暗黑的文字颜色") .foregroundColor(light: .purple, dark: .pink) .background(Color(nsColor: .quaternaryLabelColor)) // 使用以前 NSColor...

```swift struct PlayStepperView: View { @State private var count: Int = 0 var body: some View { Stepper(value: $count, step: 2) { Text("共\(count)") } onEditingChanged: { b in print(b) }...

```swift struct PlaySliderView: View { @State var count: Double = 0 var body: some View { Slider(value: $count, in: 0...100) .padding() Text("\(Int(count))") } } ```

![](https://user-images.githubusercontent.com/251980/156289124-bde3c73e-2a81-4043-8682-ae55a820f1aa.png) Toggle 可以设置 toggleStyle,可以自定义样式。使用示例如下 ```swift struct PlayToggleView: View { @State private var isEnable = false var body: some View { // 普通样式 Toggle(isOn: $isEnable) { Text("\(isEnable ? "开了" : "关了")")...

```swift struct PlayTabView: View { @State private var selection = 0 var body: some View { ZStack(alignment: .bottom) { TabView(selection: $selection) { Text("one") .tabItem { Text("首页") .hidden() } .tag(0) Text("two")...

![](https://user-images.githubusercontent.com/251980/156135869-7451bbc9-95b9-445f-8721-66f0aedbed70.png) 浮层有 HUD、ContextMenu、Sheet、Alert、ConfirmationDialog、Popover、ActionSheet 等几种方式。这些方式实现代码如下: ```swift struct PlaySuperposedLayerView: View { @StateObject var hudVM = PHUDVM() @State private var isShow = false @State private var isShowAlert = false @State private var isShowConfirmationDialog...

ScrollView 使用 scrollTo 可以直接滚动到指定的位置。ScrollView 还可以透出偏移量,利用偏移量可以定义自己的动态视图,比如向下向上滚动视图时有不同效果,到顶部显示标题视图等。 示例代码如下: ```swift struct PlayScrollView: View { @State private var scrollOffset: CGFloat = .zero var infoView: some View { GeometryReader { g in Text("移动了 \(Double(scrollOffset).formatted(.number.precision(.fractionLength(1)).rounded()))") .padding()...

![](https://user-images.githubusercontent.com/251980/155708552-35396dcd-f120-4498-a793-a65abd68c0a6.jpeg) 列的设置有三种,这三种也可以组合用。 * GridItem(.fixed(10)) 会固定设置有多少列。 * GridItem(.flexible()) 会充满没有使用的空间。 * GridItem(.adaptive(minimum: 10)) 表示会根据设置大小自动设置有多少列展示。 示例: ```swift struct PlayLazyVGridAndLazyHGridView: View { @State private var colors: [String:Color] = [ "red" : .red, "orange" :...