要在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上显示.请帮忙.
我想像这个图像一样显示我的视图控制器.请帮助任何人
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) 我是核心数据的新手。我只想检查核心数据中是否存在记录,然后更新其他插入。我可以插入、获取删除数据但无法更新。这是我的一段代码
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)
请帮我更新代码片段
您好我想将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
我只是想使用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) 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
虽然有这个问题的解决方案存在于互联网,但我无法这样做,我想围绕一个图像.
这个代码我正在使用:
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().但它不会来.请帮忙
以前的链接没有帮助我