小编Bas*_*sil的帖子

快速将 UIBezierPath 转换为 PKStrokePath

有没有办法将 UIBezierPath 转换为 PKStrokePath ?

例如,我将这些路径作为 UIBezierPath 如何将其转换为 PKStrokePath 以在 PKDrawing 中使用它?

let shape = UIBezierPath()
shape.move(to: CGPoint(x: 30.2, y: 37.71))
shape.addLine(to: CGPoint(x: 15.65, y: 2.08))
shape.addLine(to: CGPoint(x: 2.08, y: 37.33))
shape.move(to: CGPoint(x: 23.46, y: 21.21))
shape.addLine(to: CGPoint(x: 8.36, y: 21.02))
Run Code Online (Sandbox Code Playgroud)

uibezierpath swift pencilkit

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

点击 NavigationSplitView 上的不同按钮时如何避免重建视图

我尝试过苹果示例 为您的 SwiftUI 应用程序带来强大的导航结构

所以我的代码看起来像这样

        NavigationSplitView(
            columnVisibility: $navigationModel.columnVisibility
        ) {
            List(
                categories,
                selection: $navigationModel.selectedCategory
            ) { category in
                NavigationLink(category.localizedName, value: category)
            }
            .navigationTitle("Categories")
            .toolbar {
                ExperienceButton(isActive: $showExperiencePicker)
            }
        } detail: {
            NavigationStack(path: $navigationModel.recipePath) {
                RecipeGrid(category: navigationModel.selectedCategory)
            }
        }
Run Code Online (Sandbox Code Playgroud)

详情查看

struct RecipeGrid: View {
    var category: Category?
    var dataModel = DataModel.shared

    var body: some View {
        ZStack {
            if let category = category {
                ScrollView {
                    LazyVGrid(columns: columns) {
                        ForEach(dataModel.recipes(in: category)) { recipe in
                            NavigationLink(value: recipe) {
                                RecipeTile(recipe: recipe)
                            }
                            .buttonStyle(.plain) …
Run Code Online (Sandbox Code Playgroud)

swiftui swiftui-navigationlink swiftui-navigationsplitview swiftui-navigationstack

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

如何使用 PDFkit 检测滚动到 PDF 中的另一页

我正在尝试添加当前页码,因此当用户滚动到另一个页面时,它将显示例如 2 of 3(如果 pdf 有 3 页)

现在,我使用此代码

它将始终显示 1 of 3

我认为 PDFkit 使用 UIScrollView 所以我需要到达 ScrollView 这样我可以在滚动到另一个页面时检测到然后增加当前页码

我没有找到任何方法来达到 PDFkit 中的滚动视图

 func showCurrentPageIndex(){

        guard let totalPages = pdfContainerView.document?.pageCount else {return}
        guard let currentPage = pdfContainerView.currentPage else {return}
        guard let currentPageRef = currentPage.pageRef else {return}

let pageIndex = currentPageRef.pageNumber

      totalPageNumbers.text = "\(totalPages)"
      currentPageIndex.text =  "\(pageIndex)"
    }
Run Code Online (Sandbox Code Playgroud)

pdfkit uiscrollview swift

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

我不能在正则表达式中包含'符号

我尝试将'符号包含在正则表达式中

我用这个功能

func matches(for regex: String, in text: String) -> [String] {

    do {
        let regex = try NSRegularExpression(pattern: regex)
        let results = regex.matches(in: text,
                                    range: NSRange(text.startIndex..., in: text))
        return results.map {
            text.substring(with: Range($0.range, in: text)!)
        }
    } catch let error {
        print("invalid regex: \(error.localizedDescription)")
        return []
    }
}
Run Code Online (Sandbox Code Playgroud)

和这个正则表达式

    let matched = matches(for: "^[‘]|[0-9]|[a-zA-Z]+$", in: string)
Run Code Online (Sandbox Code Playgroud)

当我搜索时,我可以找到数字和英文字母

但不是'符号

string swift swift4 ios11

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

使用 AttributedString SwiftUI 3 无法进行文本对齐

AttributedString我尝试使用SwiftUI 3 中的新功能

我想改变对齐方式,但它不起作用。其他任何事情都工作正常,例如我尝试使用属性字符串更改颜色,它确实有效!但我无能为力paragraphStyle

struct ContentView: View {
    var body: some View {
       
        ZStack {
            
            Color(uiColor: UIColor(red: 0.92, green: 0.92, blue: 0.92, alpha: 1.00)).ignoresSafeArea()
                        
            VStack {
                
                Text("""
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but …
Run Code Online (Sandbox Code Playgroud)

nsattributedstring swift swiftui attributedstring

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