我尝试使用.ignoresSafeArea() ,但没有成功。
iOS 16 和早期版本中的内容视图周围没有填充。
struct CommonDailyEyeTipsWidget: Widget {
let kind: String = "CommonDailyEyeTipsWidget"
init() {
//setup firebase
FirebaseApp.configure()
}
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
Rectangle()
.foregroundStyle(Color.primary)
.ignoresSafeArea() // Does not work
.containerBackground(.accent, for: .widget)
}
.contentMarginsDisabled()
.configurationDisplayName("My Widget")
.description("This is an example widget.")
}
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试测试当前 iOS16 Beta 上的新 AppIntents API。查看文档,实现似乎非常简单,但实现后,我在快捷方式应用程序中没有看到我的 AppIntent。该设备运行的是 iOS 16.0。
这就是我实现 AppIntent 的方式:
import AppIntents
struct DoSomethingIntent: AppIntent {
static var title: LocalizedStringResource = "This will do something"
static var description = IntentDescription("Does something")
func perform() async throws -> some PerformResult {
return .finished(value: "Done")
}
}
Run Code Online (Sandbox Code Playgroud)
根据文档,快捷方式应用程序应该能够在安装我的应用程序后找到我的 AppIntent,但我发现情况并非如此。有谁知道我的实施缺少什么?
我目前正在为我的应用程序设计一个小部件,基本上,该小部件应由三个按钮组成。到目前为止,我还没有找到任何关于如何向 iOS Widget 扩展添加按钮的教程。我看到例如谷歌地图在其小部件中使用按钮。
如何才能做到这一点?
我想在我的自定义视图周围保持相同的插图。需要外部圆角半径来更改我们自定义视图的圆角半径,
我找不到任何环境变量或任何其他方式来获取小部件本身的角半径。
.cornerRadius()所有设备。由于不同的设备可能对其小部件使用不同的半径。 var body: some View {
VStack {
HStack {
VStack {
Text("Hello")
.font(.title)
Text("Widget")
}
.padding()
.background(Color.yellow)
.cornerRadius(10)//<=here
Spacer()
}
Spacer()
}
.padding(5.0)
}
Run Code Online (Sandbox Code Playgroud) 如何使用组合框架替换当用户点击表视图单元格的按钮时调用的关闭或委托回调?
问题 - 如果从视图控制器添加 Subscriber 并将返回的 AnyCancellable 存储在 Set 中;1.anyCancellable 的存储随着单元格返回而变高 0.2。当用户点击单元格的一个按钮时,许多订阅者都会收到价值
我使用内置订阅者接收器
在视图控制器中
var myAnyCancellableSet: Set<AnyCancellable> = []
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "mycell")
cell.doSomethingSubject.sink {
print("user tap button on cell")
}.store(in: &myAnyCancellableSet)
return cell
}
Run Code Online (Sandbox Code Playgroud)
在表格视图单元格中
import UIKit
import Combine
class MyTableViewCell: UITableViewCell {
private lazy var myDoSomethingSubject = PassthroughSubject<Void, Never>()
lazy var doSomethingSubject = myDoSomethingSubject.eraseToAnyPublisher()
@IBAction func buttonTapped(_ sender: UIButton) {
myDoSomethingSubject.send()
}
}
Run Code Online (Sandbox Code Playgroud)