referenceSizeForHeaderInSection标签的偏移量

时间:2019-01-11 08:59:39

标签: constraints collectionview uiedgeinsets

我想将标头部分的标签向右放置160px以与collectionView对齐。 collectionView的左右边距为160px。

enter image description here

扩展名SearchItemExplorerViewController {

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    var collectionViewWidth: CGFloat = view.frame.width

    if traitCollection.horizontalSizeClass == .regular {
        collectionViewWidth = shoudHaveMargin && isRunningInFullScreen ? view.frame.width - 320 : view.frame.width
        return CGSize(width: collectionViewWidth, height: 56)
    }

    return CGSize(width: collectionViewWidth, height: 80)
}

override func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
    return super.collectionView(collectionView, layout: collectionViewLayout, insetForSectionAt: section)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    let display: CGFloat = displayMode == . grid ? 50.0 : 0.0
    let label:UILabel = UILabel(frame: CGRect(x: 160, y: 0, width: collectionView.frame.width - 320, height: display))
    label.numberOfLines = 1
    label.lineBreakMode = NSLineBreakMode.byWordWrapping
    label.font = UIFont(name: "Helvetica", size: 17.0)
    //label.text = textForHeader(inSection: section)


    return CGSize(width: collectionView.bounds.width - 320, height: display)
}

}

在标头部分添加标签似乎是一种好方法吗?

0 个答案:

没有答案