【问题标题】:In UICollectionViewCell need to set border effect where it cross to each others (Junction type)在 UICollectionViewCell 中需要设置边界效果,它相互交叉(Junction 类型)
【发布时间】:2017-08-18 08:18:48
【问题描述】:

我实现了 UICollectionViewCell。现在我需要设置边界效果,使单元格相互交叉,如连接点。

这是图片,我需要像这样设置边框..

我尝试给单元格边框,但在输出中出现了左右边框,这不是我想要的输出。 所以我的输出看起来像这样。 (错误输出)

所以请帮帮我..

【问题讨论】:

  • 我想一旦你根据你的边界颜色设置 UICollectionView 背景颜色。愿你的问题得到解决。试试看。
  • @YagneshDobariya 我已经检查了更改的背景颜色,但是当时滚动时背景颜色可见
  • 为此,您可以从 Storyboard 或以编程方式禁用 UICollection 中的反弹效果。
  • 你想达到parallax effect吗?或者只是一个static border
  • @Joe Just 静态边框..

标签: ios swift uicollectionview uicollectionviewcell uicollectionviewlayout


【解决方案1】:

注意:以下答案基于问题所有者和我自己之间的讨论。

您需要正确设置collectionViewFlowLayout 以实现所需的输出。试试下面的代码:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    // All the values are changable according to your needs.
    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsets.zero
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 2
    return CGSize(width: (self.collectionView.frame.width / 2) - 1 , height:(self.collectionView.frame.height / 3) - 1)
}

更新1:计算布局包括navigationBarStatusBar

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
    // All the values are changable according to your needs.
    let layout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsets.zero
    layout.minimumInteritemSpacing = 1
    layout.minimumLineSpacing = 2
    return CGSize(width: (self.collectionView.frame.width / 2) - 1 , height:(((self.view.frame.height - ((navigationController?.navigationBar.frame.height)! + UIApplication.shared.statusBarFrame.height)) / 3) - 1))
}

您可能需要验证 viewDidLayoutSubviewsviewWillLayoutSubviews 中的 collectionView 框架

 override func viewDidLayoutSubviews() {
 collectionView.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: view.frame.height)
}

以下链接可以帮助您了解collectionViewFlowLayout

Enforce collectionView to have only 2 rows

uicollectionview remove top padding

Adjust cellsize for fit all screens?

注意:以后,请用相关代码发布您的问题并清楚地说明问题。

【讨论】:

    【解决方案2】:

    设置边框不会得到想要的结果。 enter image description here

    cgfloat intcellSize = ([[UIScreen mainScreen] bounds].size.width/3)-0.8;

    现在在这个方法里面定义它:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
     if ((mutArrContact.count%3) == 0) {
    
                return (mutArrContact.count/3) * intcellSize ;
            }
            else
            {
                return ((mutArrContact.count/3) * intcellSize)+ intcellSize;
            }
    
    }
    
    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
        return CGSizeMake (intcellSize,intcellSize);
    }
    

    这是为了将 3 个单元格替换为所需的结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 1970-01-01
      • 2018-09-03
      相关资源
      最近更新 更多