小编Pon*_*sti的帖子

SwiftUI:如何创建具有相同行数和列数的 LazyGrid?

我正在尝试SwiftUI 2使用新的基元LazyVGrid/创建一个网格LazyHGrid

我的目标是创建一个具有以下属性的网格:

  • 每个单元格的宽度和高度相同(基本上是一个正方形)
  • 网格具有相同数量的行和列(列 = 行)
  • 内容不应该是可滚动的,并且始终适合我的视图/屏幕的大小。

这是一个包含预期结果的视频。这是通过Grid使用 的自定义对象来实现的GeometryReader

在此输入图像描述

我尝试过.contentMode(1, .fit)将比例限制LazyVGrid为 1:1,但似乎不起作用。红色背景代表网格的框架,这不是预期的行为。

LazyVGrid(columns: [GridItem(.adaptive(minimum: 32), spacing: 0)], spacing: 0) {
    ForEach(1...100, id: \.self) { item in
        Rectangle()
            .aspectRatio(1, contentMode: .fit)
            .border(Color.black)
    }
}
.aspectRatio(1, contentMode: .fit)
.background(Color.red)
Run Code Online (Sandbox Code Playgroud)

网格尝试

我也尝试过使用GeometryReader来修复 的大小LazyVGrid,但它仍然不起作用。关于如何实现这一目标还有其他想法吗?

ios swift swiftui

5
推荐指数
2
解决办法
7822
查看次数

SwiftUI 自定义图像修改器

我正在尝试创建一个使用该resizable()函数的自定义图像修改器,因此我content应该是一个Image. 至少,我是这么认为的。

错误消息类型“IconModifier”不符合协议“ViewModifier”

struct IconModifier: ViewModifier {
    func body(content: Image) -> some View {
        content
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 10, height: 10, alignment: .center)
    }
}
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

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

FirebaseStorage无法为元数据创建downloadURL

我正在尝试使用Firebase云存储和实时数据库.在第一个我上传图像然后我尝试将downloadUrl保存在后者中.在使用MLKit将Firebase pod更新到5.0.0之前,一切正常.在StorageService中,我上传图像(可以在firebase控制台上看到它,然后在PostService中创建一个满足我所有需求的字典)

struct StorageService {
    static func uploadImage(_ image: UIImage, at reference: StorageReference, completion: @escaping (URL?) -> Void) {
        guard let imageData = UIImageJPEGRepresentation(image, 0.5) else {
            return completion(nil)
        }
        reference.putData(imageData, metadata: nil, completion: { (metadata, error) in
            if let error = error {
                assertionFailure(error.localizedDescription)
                return completion(nil)
            }
            completion(metadata?.downloadURL())
        })
    }
}
Run Code Online (Sandbox Code Playgroud)

struct PostService {
    static func create(for image: UIImage) {
        let imageRef = StorageReference.newPostImageReference()
        StorageService.uploadImage(image, at: imageRef) { (downloadURL) in
            guard let downloadURL = downloadURL else {
                return
            } …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-storage

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

标签 统计

ios ×3

swift ×3

swiftui ×2

firebase ×1

firebase-storage ×1