【问题标题】:Swift tableHeaderView autolayout issueSwift tableHeaderView 自动布局问题
【发布时间】:2018-09-30 09:06:38
【问题描述】:

我现在几乎被这个问题困住了一段时间。 我正在使用 自定义视图 (CollectionView) 作为 tableHeaderView(蓝色矩形),我想在使用自动布局时添加一些边距,但似乎没有任何效果

我试过了

  NSLayoutConstraint(item: homeCarousel, attribute: .topMargin, 
     relatedBy: .equal, toItem: self, attribute: .topMargin, 
     multiplier: 1.0, constant: 20).isActive = true
 ------
  homeCarousel.topAnchor.cons.....

【问题讨论】:

    标签: swift uitableview ios-autolayout


    【解决方案1】:

    您不能直接向 UITableView 的标题视图添加边距。使用简单的 UIView 作为容器(紫色视图)并将 CollectionView(绿色)嵌套在其中。然后,您将能够使用情节提要或在代码中设置约束。

    See screenshot here

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 2018-09-15
      • 2015-03-20
      • 2015-03-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多