gpt4 book ai didi

ios - Collection View 内的按钮不会在点击时突出显示

转载 作者:搜寻专家 更新时间:2023-11-01 07:13:35 54 4
gpt4 key购买 nike

我在 Collection View 中有一个按钮,但与应用程序周围的其他按钮不同,当您点击它时,它不会突出显示。我已经尝试了一些建议的事情,例如在按钮上打开 Shows Touch on Highlight,并将 delaysContentTouches 设置为 false。

func createCollectionView() {
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 15, left: 10, bottom: 10, right: 10)
layout.itemSize = CGSize(width: view.frame.width, height: 50)

cv = UICollectionView(frame: view.frame, collectionViewLayout: layout)
cv.frame = CGRectMake(0, 50, view.frame.width, 250);
cv.dataSource = self
cv.delegate = self
cv.registerNib(UINib(nibName: "cvCell", bundle: nil), forCellWithReuseIdentifier: "cell")
cv.backgroundColor = UIColor.whiteColor()

//suggested on other SO answers:
cv.delaysContentTouches = false

for view in cv.subviews {
if view is UIScrollView {
(view as? UIScrollView)!.delaysContentTouches = false
break
}
}
}


//Button:
var onTap: ((cvCell) -> Void)?
@IBAction func btn(sender: AnyObject) {
onTap?(self)
}

//CollectionView select:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! cvCell
cell.btn.setTitle("follow", forState: .Normal)
}

有什么想法吗?

最佳答案

如果您的按钮类型是 cell.btn.buttonType == UIButtonType.system 则它会自动突出显示按钮标题上的效果。否则 cell.btn.buttonType == UIButtonType.custom 比你需要给自己的高亮效果。

enter image description here

关于ios - Collection View 内的按钮不会在点击时突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43579795/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com