SwiftUI使用
查询超过两次的必须记录😂
方法
常规
预览显示暗黑模式 .environment(\.colorScheme, .dark)
/// push 跳转
@State var selection: Int? = nil
NavigationLink(destination: TOMainView(), tag: 1, selection: $selection) {
Button(action: {
self.selection = 1
}) {
Text("Get Started")
.frame(minWidth: 220)
.font(.system(size: 24, weight: .semibold))
.padding()
.foregroundColor(Color(uiColor: UIColor(rgb: 0x6644ab)))
.overlay(
RoundedRectangle(cornerRadius: 25)
.stroke(Color.white, lineWidth: 0)
)
}
.background(Color.white.opacity(0.85)) // If you have this
.cornerRadius(25)
}
/// 直接更换vc
if let window = UIApplication.shared.windows.first {
window.rootViewController = UIHostingController(rootView: HomeScreen())
window.makeKeyAndVisible()
}
ObservedObject,StateObject,EnvironmentObject
@state,wrapped reference,系统自动update ui
@binding,binding type 链接 state object
Struct作为数据源,某一个property更改,会mutate整个struct,因为它是valuetype
ObservableObject不存储数据,class可以继承为此类型,然后定义@published属性,@ObservedObject就让@published产生一个类似@state的属性
StateObject存储数据
EnvironmentObject
- environmentObject(_:),存
- @EnvironmentObject,取
list等局部刷新
iOS13后出了 tableView collectionView 的 Diffable Data Sources,可以方便的管理刷新了。
但是swiftui里怎么操作的
- 学学这研究素质Understanding how and when SwiftUI decides to redraw views
- SwiftUI 合理使用 EquatableView
- The Mystery Behind View Equality
网络访问及retry按钮
客户端请求的队列话,失败retry,及主动取消?类似tweetbot的发送失败,顶部浮窗点击后一键重试
normalHTTP Request
AdvancedMVVM & Networking with SwiftUI and Combine
AdvancedError Handling with Combine and SwiftUI
loading及Redacted Placeholder
多语言
Localized SwiftUI Views in a Swift Package
SwiftUI: Localization on the Fly
apple login
SwiftUI Sign in With Apple
Sign in with Apple -SwiftUI
参考
SwiftUI: How to get content offset from ScrollView
自定一个badgeSwiftUI Tutorial: Showing Badge on Tab Bar Item
貌似不能改tabbarimage的位置SwiftUI: Adjusting position of Image in a TabView
Building Grid Layouts Using LazyVGrid and LazyHGrid
SwiftUI main list scrollable header view without sections?
prefersLargeTitles 时候,如果有 rightbaritem,怎么对齐?How To Build Resizing Image In Navigation Bar With Large Title