我正在尝试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
,但它仍然不起作用。关于如何实现这一目标还有其他想法吗?
我正在尝试创建一个使用该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) 我正在尝试使用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)