SwiftUI Button按钮组件

SwiftUI 的Button是开发者日常用来响应点击事件的核心组件之一,蛮好用的。你可以通过语法创建按钮,像这样:

Button(action: { // 执行动作 }) { Text("点击我") }
,按钮的内容可以随便定义,甚至是图片、文本等。Button的样式也挺多,想要简洁一点,使用.plain,要做成突出效果的话,用.borderedProminent就好。
如果你想要按钮的点击状态反馈,可以通过.foregroundColor.padding等修饰符来自定义视觉效果。还可以根据需要禁用按钮:
Button("点击我") { // Action }.disabled(isDisabled)
。嗯,,Button挺方便的,不管是交互,还是复杂的按钮效果,都可以通过它来实现。如果你是初次接触 SwiftUI 的开发者,可以尝试搭配其他视图来打造更酷的交互效果!

zip
SwiftUI—Button.zip 预估大小:16个文件
folder
SwiftUI—Button 文件夹
file
.DS_Store 6KB
folder
SwiftUIDemo 文件夹
file
.DS_Store 6KB
folder
SwiftUIDemo 文件夹
folder
Preview Content 文件夹
folder
Preview Assets.xcassets 文件夹
file
Contents.json 63B
file
SwiftUIDemoApp.swift 412B
file
Persistence.swift 2KB
file
ContentView.swift 3KB
folder
Assets.xcassets 文件夹
file
Contents.json 63B
folder
AppIcon.appiconset 文件夹
file
Contents.json 2KB
folder
AccentColor.colorset 文件夹
file
Contents.json 123B
folder
SwiftUIDemo.xcdatamodeld 文件夹
folder
SwiftUIDemo.xcdatamodel 文件夹
file
contents 632B
file
.xccurrentversion 264B
folder
SwiftUIDemo.xcodeproj 文件夹
file
project.pbxproj 14KB
folder
xcuserdata 文件夹
folder
zhaoshijun.xcuserdatad 文件夹
folder
xcschemes 文件夹
file
xcschememanagement.plist 346B
folder
project.xcworkspace 文件夹
folder
xcshareddata 文件夹
folder
swiftpm 文件夹
file
IDEWorkspaceChecks.plist 238B
file
contents.xcworkspacedata 135B
folder
xcuserdata 文件夹
folder
zhaoshijun.xcuserdatad 文件夹
file
UserInterfaceState.xcuserstate 26KB
zip 文件大小:34.69KB