【发布时间】:2019-10-24 20:54:31
【问题描述】:
我遇到了一个问题。我正在制作一个应用程序,我需要在 UICollectionView 的页脚内制作一个带有渐变颜色的按钮,问题是我无法通过情节提要制作它,所以我必须以编程方式制作它UICollectionView 的页脚内。但是不知道怎么弄。
事情是我已经尝试过,我已经完成了UICollectionView的Footer中UIButton的基本结构。
case UICollectionView.elementKindSectionFooter:
let footer = outerMainCollectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Footer", for: indexPath) as! headerReusableView
let button = UIButton(frame: CGRect(x: 0, y: 0, width: collectionView.frame.width - 50, height: 40))
if isGuest {
button.backgroundColor = .red
} else {
button.backgroundColor = .black
}
button.setTitle("ALL", for: .normal)
button.setTitleColor(COLORWHITE, for: .normal)
button.addTarget(self, action: #selector(footerButton), for: .touchUpInside)
footer.addSubview(button)
footer.backgroundColor = UIColor.green
return footer
我想让它在浅橙色和深橙色之间渐变,例如使用任何十六进制值,并且我想让它的中心高度为 40,并从所有侧面设置边距 - 顶部、底部、左侧、右侧。
【问题讨论】:
-
这段代码放在哪里?告诉我们
headerReusableView类 -
headerReusableView 与我的问题无关,所以我没有在这里写下来。我已经得到了我的问题的答案。顺便说一句,谢谢你的反对票。 :-)
-
我问是因为看起来你每次出列页脚时都会添加一个按钮,这非常糟糕;顺便说一句,我没有投反对票-.-
标签: ios swift uicollectionview uibutton