小编Nat*_*cks的帖子

How can I run an action when a state changes?

enum SectionType: String, CaseIterable {
    case top = "Top"
    case best = "Best"
}

struct ContentView : View {
    @State private var selection: Int = 0

    var body: some View {
        SegmentedControl(selection: $selection) {
            ForEach(SectionType.allCases.identified(by: \.self)) { type in
                Text(type.rawValue).tag(type)
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

How do I run code (e.g print("Selection changed to \(selection)") when the $selection state changes? I looked through the docs and I couldn't find anything.

state ios swift swiftui

8
推荐指数
5
解决办法
2167
查看次数

列表视图确实很慢而且很慢

我正在将约500行数据加载到中List。当我有10行时还可以,但是现在我有500行,这非常慢。有什么我可以做的来改善它的性能吗?

        List {
            SegmentedControl(selection: $feedType) {
                ForEach(FeedType.allCases.identified(by: \.self)) { type in
                    Text(type.rawValue)
                }
            }

            ForEach(store.stories) { story in
                NavigationButton(destination: Text("")) {
                    StoryRow(story: story)
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

5
推荐指数
0
解决办法
336
查看次数

How do I change text size and field size of a TextField?

I'm trying to create an input similar like this (?) with SwiftUI.

在此处输入图片说明

I've made progress but I can't figure out how to change the height of the text fields and make the input text size bigger.

在此处输入图片说明

ios swift swiftui

3
推荐指数
1
解决办法
1397
查看次数

如何将视图固定在屏幕边缘?

如何将视图(在这种情况下为标签/文本)固定到屏幕的边缘SwiftUI?使用情节提要,我只会使用,AutoLayout但无法使用SwiftUI

在此处输入图片说明

ios swift swiftui

1
推荐指数
1
解决办法
546
查看次数

如何在SwiftUI中使用SFSafariViewController?

我正在尝试SFSafariViewController从a 呈现一个,NavigationButton但是我不确定如何使用SwiftUI。

在UIKit中,我只会做:

let vc = SFSafariViewController(url: URL(string: "https://google.com"), entersReaderIfAvailable: true)
    vc.delegate = self

    present(vc, animated: true)
Run Code Online (Sandbox Code Playgroud)

safari ios swift swiftui

1
推荐指数
3
解决办法
845
查看次数

标签 统计

ios ×5

swift ×5

swiftui ×5

safari ×1

state ×1