小编Gor*_*per的帖子

如何在所有设备中使用swift4在CollectionView中显示两列

在此输入图像描述

要在collectionView中只显示两列,我正在使用这段代码

    let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
    layout.minimumInteritemSpacing = 4
    layout.itemSize = CGSize(width:(self.collectionView.frame.size.width - 10)/2,height: (self.collectionView.frame.size.height)/3)
Run Code Online (Sandbox Code Playgroud)

但它只能在5s上正常显示,而不是在每个iphone上显示.请帮忙.

我想像这个图像一样显示我的视图控制器.请帮助任何人

在此输入图像描述

ios uicollectionview swift swift4

5
推荐指数
3
解决办法
6018
查看次数

使用 Swift 4 中的 where Query 从 Firebase 检索数据

图片

let ref = Database.database().reference(withPath: "user")
ref.observeSingleEvent(of: .value, with: { snapshot in

    if !snapshot.exists() { return }

    print(snapshot) // Its print all values including Snap (User)

    print(snapshot.value!)

    let username = snapshot.childSnapshot(forPath: "full_name").value
    print(username!)

})
Run Code Online (Sandbox Code Playgroud)

firebase firebase-realtime-database swift4

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

在 Core Data 中,如何在 swift 4 中执行“如果存在更新其他插入”?

我是核心数据的新手。我只想检查核心数据中是否存在记录,然后更新其他插入。我可以插入、获取删除数据但无法更新。这是我的一段代码

var context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
var user = [Users]()
func insertData() {

    let newUser = NSEntityDescription.insertNewObject(forEntityName: "Users", into: context)//entity(forEntityName: "Users", in: context)
    newUser.setValue("chatt", forKey: "name")
    newUser.setValue("100", forKey: "balance")
    newUser.setValue("123", forKey: "user_id")
    do {

        try context.save()

    } catch {

        print("Failed saving")
    } 
}
Run Code Online (Sandbox Code Playgroud)

请帮我更新代码片段

core-data ios swift

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

如何使用swift 4显示像facebook上传图像的collectionView?

在此输入图像描述在此输入图像描述

您好我想将collectionView完全显示为上图.我知道它负责UICollectionViewFlowLayout,但无法做到.非常感谢帮助.这是我的代码

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
     let yourWidth = (collectionView.bounds.width - 4) / 3.0
     let yourHeight = yourWidth
     return CGSize(width: yourWidth, height: yourHeight)
}
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview swift swift4 uicollectionviewflowlayout

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

如何使用swift在firebase上上传多个图像?

我只是想使用swift在firebase上上传多个图像.我现在正在上传一张图片但无法上传多张图片.这是我的代码

let photoIdString = NSUUID().uuidString
let storageRef = Storage.storage().reference(forURL: Config.STORAGE_ROOF_REF).child("posts").child(photoIdString)
storageRef.putData(imageData, metadata: nil,completion: {(metadata,error) in

       if error != nil {
            return
       }
       let photoUrl = metadata?.downloadURL()?.absoluteString
       let ref = Database.database().reference()
       let postReference = ref.child("posts")
       let newPostId = postReference.childByAutoId().key
       let newPostReference = postReference.child(newPostId)
       newPostReference.setValue(["photoUrl":photoUrl,"caption":self.textView.text!]) 
Run Code Online (Sandbox Code Playgroud)

ios firebase swift firebase-storage

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

如何在所有设备中使用 swift4 在 CollectionView 中显示三列

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    
    
    if collectionView == self.collectionViewVideo {

        var collectionViewSize = collectionViewVideo.frame.size
        collectionViewSize.width = collectionViewSize.width/3.0 //Display Three elements in a row.
        return collectionViewSize
    } else {
        return CGSize(width: 60, height: 60)
    }
    
    
}
Run Code Online (Sandbox Code Playgroud)

我想像这样展示我的收藏视图

ios uicollectionview swift swift4 uicollectionviewflowlayout

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

如何在swift 4中进行图像查看

在此输入图像描述虽然有这个问题的解决方案存在于互联网,但我无法这样做,我想围绕一个图像.

这个代码我正在使用:

extension UIImageView {        
    func makeRounded() {
        let radius = self.frame.width/2.0
        self.layer.cornerRadius = radius
        self.layer.masksToBounds = true
    }
 }
Run Code Online (Sandbox Code Playgroud)

然后我在viewdidload()中调用此函数,如imgvw.makeRounded().但它不会来.请帮忙

以前的链接没有帮助我

uiimageview uiimage ios swift swift4

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