小编Mar*_*rko的帖子

如何设置单元格间距和UICollectionView - UICollectionViewFlowLayout大小比例?

我想加入UICollectionViewViewController了,我需要有"每行" 3个细胞无细胞之间的空格(它应该看起来像一个网格).单元格宽度应该是屏幕尺寸的三分之一,所以我认为layout.item宽度应该相同.但后来我明白了:

layout.itemSize width = screenSize.width/3

如果我减小那个尺寸(例如78像素),那就更好了,但是行中的第三个单元格不是完全可见的,我仍然有那个空白区域(顶部和底部,左侧和右侧).

在此输入图像描述

class ViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
    var collectionView: UICollectionView?
    var screenSize: CGRect!
    var screenWidth: CGFloat!
    var screenHeight: CGFloat!

    override func viewDidLoad() {
        super.viewDidLoad()

        screenSize = UIScreen.mainScreen().bounds
        screenWidth = screenSize.width
        screenHeight = screenSize.height

        // Do any additional setup after loading the view, typically from a nib
        let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
        layout.sectionInset = UIEdgeInsets(top: 20, left: 0, bottom: 10, right: 0)
        layout.itemSize = CGSize(width: screenWidth / 3, height: …
Run Code Online (Sandbox Code Playgroud)

uicollectionview uicollectionviewcell uicollectionviewlayout swift

122
推荐指数
6
解决办法
15万
查看次数

如何在Swift中获取父ViewController的类名?

有没有办法在现在(孩子)获得父VC的班级名称UIViewController?我的'孩子'VC(推)有两个'父母' UIViewController,所以我想知道哪一个是现在的父母?

uiviewcontroller swift

18
推荐指数
2
解决办法
3万
查看次数

在Swift中将AVAudioPlayer输出更改为扬声器?

我在我的iPhone应用程序中有简单的AVAudioPlayer,它可以工作,但输出应该是手机扬声器而不是耳机.我在这里找到了类似的主题,但不知道如何将其"翻译"为swift(AudioSessionSetProperty令我困惑)?

var audioPlayer = AVAudioPlayer(data: fileData, error: &playbackError) 
//fileData is url to file

if let player = audioPlayer{
    player.delegate = self

    if(player.prepareToPlay() && player.play()){
         println("Started playing the recorded audio")
    } else {
         println("Could not play the audio")
    }
}
Run Code Online (Sandbox Code Playgroud)

iphone avaudioplayer ios swift

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