UICollectionViewFlowLayout minimumLineSpacing 不适用于整个集合视图 - Swift [英] UICollectionViewFlowLayout minimumLineSpacing not applied to whole collection view - Swift

查看:58
本文介绍了UICollectionViewFlowLayout minimumLineSpacing 不适用于整个集合视图 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为日历创建 UIView 子类,其中带有流布局的 UICollectionView 用于显示日期.代码是:

I'm creating UIView subclass for calendar, wherein UICollectionView with flow layout is used to display dates. The code is :

    override func draw(_ rect: CGRect)
    {
        super.draw(rect)
        .
        .

        configureCalendarView()
        .
    }



    func configureCalendarView()
    {
        cellWd = Double(self.frame.size.width)/7.0

        let layout = UICollectionViewFlowLayout.init()
        layout.minimumLineSpacing = 0.5
        layout.minimumInteritemSpacing = 0.0
        layout.sectionInset = UIEdgeInsetsMake(1, 0, 0, 0)

        collectionV = UICollectionView.init(frame: CGRect(x: 0, y:90, width:self.frame.size.width, height:CGFloat(cellWd * 5 + 3.5)), collectionViewLayout: layout)
        collectionV?.backgroundColor = self.backgroundColor
        collectionV?.isScrollEnabled = false
        collectionV?.register(DayCell.classForCoder(), forCellWithReuseIdentifier:reuseID)
        collectionV?.dataSource = self;
        collectionV?.delegate = self;
        collectionV?.backgroundColor = calBgColor  //lightgray
        self.addSubview(collectionV!)
    }

一切正常,但最小行距在第 2 行和第 3 行之间没有任何影响.下面是截图:

Everything is working fine but minimum line spacing is not having any effect between 2nd and 3rd row. Below is the screenshot :

怎么了?任何帮助将不胜感激.谢谢!

Whats going wrong ? Any help would greatly be appreciated . Thank you !

推荐答案

layout.minimumLineSpacing = 0.5 转换为 0.5point * scale = 像素.

layout.minimumLineSpacing = 0.5 translates to 0.5point * scale = pixels.

因此,如果您在 3.0 比例的 iphone 6+ 7+ 上运行,则 0.5 将是 1.5 像素.并且在 2x 比例下将是 1 个像素.为了纠正这一点.添加这个:

So if you are running on iphone 6+ 7+ with 3.0 scale, that 0.5 will be 1.5 pixels. And on 2x scale that will be 1 pixel. To correct this. add this:

layout.minimumLineSpacing = 1.0/[UIScreen mainScreen].scale;这样您就可以保证始终获得 1 个像素的间距.

layout.minimumLineSpacing = 1.0 / [UIScreen mainScreen].scale; This way you guaranteed always get 1 pixel spacing.

layout.minimumLineSpacing = 1.0f;

CGFloat collectionWidth = self.frame.size.width;
CGFloat days = 7.0f;
CGFloat spacing = 1.0f;

CGFloat itemHeight = floorf((collectionWidth/days) - spacing;

这篇关于UICollectionViewFlowLayout minimumLineSpacing 不适用于整个集合视图 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆