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

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

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
这真让我抓狂!我有一个UICollectionViewController,如下所示:
class PhrasesCompactCollectionViewController: UICollectionViewController
Run Code Online (Sandbox Code Playgroud)
正在调用numberOfSections和cellForItemAt,但从不调用sizeForItemAtIndexPath.我在其他地方使用相同的确切代码,它正确触发.我正在使用Xcode 8 Beta 6.
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
return CGSize(width: 120, height:120)
}
Run Code Online (Sandbox Code Playgroud) 我想实现UIVisualEffectView将模糊效果应用于视图以显示其背后的视图.
这个应该有背景模糊的视图UITableViewController是嵌入在a中的UINavigationController,它将在iPad上以popover呈现,或者它将在iPhone上以模式全屏显示,这要归功于iOS 8自适应segues(Present as Popover).当这个视图控制器在弹出框中时,我希望背景模糊弹出框下面的内容,当它全屏显示时,我希望背景模糊前一个视图控制器.
我试图实现这个并且没有成功.我甚至无法使模糊效果适用于弹出窗口.我认为这段代码可以解决问题:
//In viewDidLoad on the UITableViewController subclass:
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light))
effectView.frame = tableView.frame
tableView.addSubview(effectView)
Run Code Online (Sandbox Code Playgroud)
我也尝试添加子视图tableView.backgroundView,我尝试设置backgroundView为我effectView,我尝试使用Autolayout约束而不是设置框架,但没有任何工作.你能帮助我完成所期望的行为吗?
我想要获得的一个例子:
iPad popover:

iPhone模态演示:

uitableview uipopovercontroller modalviewcontroller ios swift